use of org.evosuite.EvoSuite in project evosuite by EvoSuite.
the class DefUseAnalysisSystemTest method testSimpleExample.
@Test
public void testSimpleExample() {
EvoSuite evosuite = new EvoSuite();
String targetClass = DefUseExample1.class.getCanonicalName();
Properties.TARGET_CLASS = targetClass;
// Need to deactivate assertions, otherwise classloader is chanaged
// and DefUseCoverageFactory is reset
Properties.ASSERTIONS = false;
// Properties.ANALYSIS_CRITERIA = "Branch,DefUse";
String[] command = new String[] { "-generateSuite", "-class", targetClass };
Object result = evosuite.parseCommandLine(command);
GeneticAlgorithm<?> ga = getGAFromResult(result);
TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
System.out.println("EvolvedTestSuite:\n" + best);
Assert.assertEquals(0, DefUseCoverageFactory.getInterMethodGoalsCount());
Assert.assertEquals(0, DefUseCoverageFactory.getIntraClassGoalsCount());
Assert.assertEquals(1, DefUseCoverageFactory.getParamGoalsCount());
Assert.assertEquals(3, DefUseCoverageFactory.getIntraMethodGoalsCount());
Assert.assertEquals("Non-optimal coverage: ", 1d, best.getCoverage(), 0.001);
}
use of org.evosuite.EvoSuite in project evosuite by EvoSuite.
the class DefUseAnalysisSystemTest method testGCDExample.
@Test
public void testGCDExample() {
EvoSuite evosuite = new EvoSuite();
String targetClass = GCD.class.getCanonicalName();
Properties.ASSERTIONS = false;
String[] command = new String[] { "-generateSuite", "-class", targetClass };
Object result = evosuite.parseCommandLine(command);
System.out.println("Def: " + DefUsePool.getDefCounter());
// DefUseCoverageFactory.computeGoals();
GeneticAlgorithm<?> ga = getGAFromResult(result);
TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
System.out.println("EvolvedTestSuite:\n" + best);
Assert.assertEquals(0, DefUseCoverageFactory.getInterMethodGoalsCount());
Assert.assertEquals(0, DefUseCoverageFactory.getIntraClassGoalsCount());
// 3 or 4?
Assert.assertEquals(4, DefUseCoverageFactory.getParamGoalsCount());
Assert.assertEquals(6, DefUseCoverageFactory.getIntraMethodGoalsCount());
Assert.assertEquals("Non-optimal coverage: ", 1d, best.getCoverage(), 0.001);
}
use of org.evosuite.EvoSuite in project evosuite by EvoSuite.
the class ImplicitExplicitExceptionsSystemTest method testExceptionFitness.
private void testExceptionFitness() {
EvoSuite evosuite = new EvoSuite();
String targetClass = ImplicitExplicitException.class.getCanonicalName();
Properties.TARGET_CLASS = targetClass;
Properties.CRITERION = new Criterion[] { Properties.Criterion.EXCEPTION };
Properties.OUTPUT_VARIABLES = "" + RuntimeVariable.Explicit_MethodExceptions + "," + RuntimeVariable.Explicit_TypeExceptions + "," + RuntimeVariable.Implicit_MethodExceptions + "," + RuntimeVariable.Implicit_TypeExceptions;
String[] command = new String[] { "-generateSuite", "-class", targetClass };
Object result = evosuite.parseCommandLine(command);
GeneticAlgorithm<?> ga = getGAFromResult(result);
TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
System.out.println("EvolvedTestSuite:\n" + best);
double fitness = best.getFitness();
/*
* there are 2 undeclared exceptions (both implicit and explicit),
* and 3 declared: so fit = 1 / (1+5)
*/
Assert.assertEquals("Wrong fitness: ", 1d / 6d, fitness, 0.0000001);
Map<String, OutputVariable<?>> map = DebugStatisticsBackend.getLatestWritten();
Assert.assertNotNull(map);
Assert.assertEquals(1, map.get(RuntimeVariable.Explicit_MethodExceptions.toString()).getValue());
Assert.assertEquals(1, map.get(RuntimeVariable.Explicit_TypeExceptions.toString()).getValue());
Assert.assertEquals(1, map.get(RuntimeVariable.Implicit_MethodExceptions.toString()).getValue());
Assert.assertEquals(1, map.get(RuntimeVariable.Implicit_TypeExceptions.toString()).getValue());
}
use of org.evosuite.EvoSuite in project evosuite by EvoSuite.
the class InputCoverageFitnessFunctionSystemTest method testInputCoverage.
@Test
public void testInputCoverage() {
EvoSuite evosuite = new EvoSuite();
String targetClass = MethodWithSeveralInputArguments.class.getCanonicalName();
Properties.TARGET_CLASS = targetClass;
Properties.MAX_ARRAY = 2;
Properties.NULL_PROBABILITY = 0.2;
Properties.SEARCH_BUDGET = 20000;
String[] command = new String[] { "-generateSuite", "-class", targetClass };
Object result = evosuite.parseCommandLine(command);
GeneticAlgorithm<?> ga = getGAFromResult(result);
TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
List<?> goals = TestGenerationStrategy.getFitnessFactories().get(0).getCoverageGoals();
Assert.assertEquals(12, goals.size());
Assert.assertEquals("Non-optimal coverage: ", 1d, best.getCoverage(), 0.001);
}
use of org.evosuite.EvoSuite in project evosuite by EvoSuite.
the class MethodCoverageFitnessFunctionSystemTest method testMethodFitnessSimpleExample.
public void testMethodFitnessSimpleExample() {
EvoSuite evosuite = new EvoSuite();
String targetClass = SingleMethod.class.getCanonicalName();
Properties.TARGET_CLASS = targetClass;
String[] command = new String[] { "-generateSuite", "-class", targetClass };
Object result = evosuite.parseCommandLine(command);
GeneticAlgorithm<?> ga = getGAFromResult(result);
TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
System.out.println("EvolvedTestSuite:\n" + best);
// assuming single fitness function
int goals = TestGenerationStrategy.getFitnessFactories().get(0).getCoverageGoals().size();
Assert.assertEquals(2, goals);
Assert.assertEquals("Non-optimal coverage: ", 1d, best.getCoverage(), 0.001);
}
Aggregations