use of org.evosuite.EvoSuite in project evosuite by EvoSuite.
the class StaticBlockCoverageSystemTest method test.
// We are not instrumenting static blocks for a reason. TODO: What was the reason?
@Ignore
@Test
public void test() {
EvoSuite evosuite = new EvoSuite();
String targetClass = StaticBlockCoverage.class.getCanonicalName();
Properties.TARGET_CLASS = targetClass;
Properties.CRITERION = new Criterion[] { Criterion.LINE };
String[] command = new String[] { "-generateSuite", "-class", targetClass };
Object result = evosuite.parseCommandLine(command);
GeneticAlgorithm<?> ga = getGAFromResult(result);
TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
System.out.println(best.toString());
double best_fitness = best.getFitness();
Assert.assertEquals("Optimal coverage was not achieved ", 0.0, best_fitness, 0.0001);
}
use of org.evosuite.EvoSuite in project evosuite by EvoSuite.
the class StaticSingletonFieldSystemTest method test.
@Test
public void test() {
EvoSuite evosuite = new EvoSuite();
String targetClass = SaticSingletonField.class.getCanonicalName();
Properties.TARGET_CLASS = targetClass;
String[] command = new String[] { "-generateSuite", "-class", targetClass };
Properties.OUTPUT_VARIABLES = "" + RuntimeVariable.HadUnstableTests;
Object result = evosuite.parseCommandLine(command);
GeneticAlgorithm<?> ga = getGAFromResult(result);
TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
Map<String, OutputVariable<?>> map = DebugStatisticsBackend.getLatestWritten();
Assert.assertNotNull(map);
OutputVariable unstable = map.get(RuntimeVariable.HadUnstableTests.toString());
Assert.assertNotNull(unstable);
Assert.assertEquals("Unexpected unstabled test cases were generated", Boolean.FALSE, unstable.getValue());
double best_fitness = best.getFitness();
Assert.assertTrue("Optimal coverage was not achieved ", best_fitness == 0.0);
}
use of org.evosuite.EvoSuite in project evosuite by EvoSuite.
the class TestSuiteMinimizerSystemTest method testWithOneFitnessFunctionWithValueMinimization.
@Test
public void testWithOneFitnessFunctionWithValueMinimization() {
Properties.CRITERION = new Criterion[1];
Properties.CRITERION[0] = Criterion.ONLYBRANCH;
Properties.MINIMIZE_VALUES = true;
Properties.MINIMIZE_SKIP_COINCIDENTAL = false;
Properties.MINIMIZE_SECOND_PASS = false;
EvoSuite evosuite = new EvoSuite();
String targetClass = MethodReturnsPrimitive.class.getCanonicalName();
Properties.TARGET_CLASS = targetClass;
String[] command = new String[] { "-generateSuite", "-class", targetClass };
Object result = evosuite.parseCommandLine(command);
Assert.assertNotNull(result);
GeneticAlgorithm<?> ga = getGAFromResult(result);
TestSuiteChromosome c = (TestSuiteChromosome) ga.getBestIndividual();
System.out.println(c.toString());
Assert.assertEquals(0.0, c.getFitness(), 0.0);
Assert.assertEquals(1.0, c.getCoverage(), 0.0);
Assert.assertEquals(6.0, c.getNumOfCoveredGoals(ga.getFitnessFunction()), 0.0);
Assert.assertEquals(5, c.size());
}
use of org.evosuite.EvoSuite in project evosuite by EvoSuite.
the class MockUdpSystemTest method testReceiveUdp.
@Test
public void testReceiveUdp() {
EvoSuite evosuite = new EvoSuite();
String targetClass = ReceiveUdp.class.getCanonicalName();
Properties.TARGET_CLASS = targetClass;
Properties.SEARCH_BUDGET = 20000;
Properties.VIRTUAL_NET = true;
String[] command = new String[] { "-generateSuite", "-class", targetClass };
Object result = evosuite.parseCommandLine(command);
Assert.assertTrue(result != null);
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("Wrong number of goals: ", 3, goals);
Assert.assertEquals("Non-optimal coverage: ", 1d, best.getCoverage(), 0.001);
}
use of org.evosuite.EvoSuite in project evosuite by EvoSuite.
the class MockClockSystemTest method testClock.
@Test
public void testClock() throws Exception {
String targetClass = ClockExample.class.getCanonicalName();
Properties.TARGET_CLASS = targetClass;
Properties.JUNIT_TESTS = true;
Properties.JUNIT_CHECK = true;
Properties.REPLACE_CALLS = true;
Properties.OUTPUT_VARIABLES = "" + RuntimeVariable.HadUnstableTests;
EvoSuite evosuite = new EvoSuite();
String[] command = new String[] { "-generateSuite", "-class", targetClass };
Object result = evosuite.parseCommandLine(command);
GeneticAlgorithm<?> ga = getGAFromResult(result);
TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
Assert.assertNotNull(best);
Assert.assertEquals("Non-optimal coverage: ", 1d, best.getCoverage(), 0.001);
checkUnstable();
}
Aggregations