Search in sources :

Example 31 with TestSuiteChromosome

use of org.evosuite.testsuite.TestSuiteChromosome in project evosuite by EvoSuite.

the class OutputCoverageFitnessFunctionSystemTest method testOutputCoverageIgnoreHashCode.

@Test
public void testOutputCoverageIgnoreHashCode() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = ClassWithHashCode.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();
    int goals = 0;
    for (TestFitnessFactory ff : TestGenerationStrategy.getFitnessFactories()) goals += ff.getCoverageGoals().size();
    Assert.assertEquals("Unexpected number of goals", 2, goals);
    Assert.assertEquals("Non-optimal fitness: ", 0.0, best.getFitness(), 0.001);
    Assert.assertEquals("Non-optimal coverage: ", 1d, best.getCoverage(), 0.001);
}
Also used : EvoSuite(org.evosuite.EvoSuite) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) MethodReturnsObject(com.examples.with.different.packagename.coverage.MethodReturnsObject) TestFitnessFactory(org.evosuite.coverage.TestFitnessFactory)

Example 32 with TestSuiteChromosome

use of org.evosuite.testsuite.TestSuiteChromosome in project evosuite by EvoSuite.

the class OutputCoverageFitnessFunctionSystemTest method testOutputCoveragePrimitiveTypes.

public void testOutputCoveragePrimitiveTypes() {
    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);
    GeneticAlgorithm<?> ga = getGAFromResult(result);
    TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
    int goals = 0;
    for (TestFitnessFactory ff : TestGenerationStrategy.getFitnessFactories()) goals += ff.getCoverageGoals().size();
    Assert.assertEquals("Unexpected number of goals", 24, goals);
    Assert.assertEquals("Non-optimal fitness: ", 0.0, best.getFitness(), 0.001);
    Assert.assertEquals("Non-optimal coverage: ", 1d, best.getCoverage(), 0.001);
}
Also used : EvoSuite(org.evosuite.EvoSuite) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) MethodReturnsObject(com.examples.with.different.packagename.coverage.MethodReturnsObject) TestFitnessFactory(org.evosuite.coverage.TestFitnessFactory)

Example 33 with TestSuiteChromosome

use of org.evosuite.testsuite.TestSuiteChromosome in project evosuite by EvoSuite.

the class OutputCoverageFitnessFunctionSystemTest method testOutputCoverageArray.

@Test
public void testOutputCoverageArray() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = MethodReturnsArray.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();
    int goals = 0;
    for (TestFitnessFactory ff : TestGenerationStrategy.getFitnessFactories()) goals += ff.getCoverageGoals().size();
    Assert.assertEquals("Unexpected number of goals", 15, goals);
    Assert.assertEquals("Non-optimal fitness: ", 0.0, best.getFitness(), 0.001);
    Assert.assertEquals("Non-optimal coverage: ", 1d, best.getCoverage(), 0.001);
}
Also used : EvoSuite(org.evosuite.EvoSuite) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) MethodReturnsObject(com.examples.with.different.packagename.coverage.MethodReturnsObject) TestFitnessFactory(org.evosuite.coverage.TestFitnessFactory)

Example 34 with TestSuiteChromosome

use of org.evosuite.testsuite.TestSuiteChromosome in project evosuite by EvoSuite.

the class OutputCoverageFitnessFunctionSystemTest method testOutputCoverageObjectType.

public void testOutputCoverageObjectType() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = MethodReturnsObject.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();
    int goals = 0;
    for (TestFitnessFactory ff : TestGenerationStrategy.getFitnessFactories()) goals += ff.getCoverageGoals().size();
    Assert.assertEquals("Unexpected number of goals", 14, goals);
    // sub-optimal due to hashcode observer
    Assert.assertEquals("Unexpected coverage: ", 0.888d, best.getCoverage(), 0.001);
}
Also used : EvoSuite(org.evosuite.EvoSuite) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) MethodReturnsObject(com.examples.with.different.packagename.coverage.MethodReturnsObject) TestFitnessFactory(org.evosuite.coverage.TestFitnessFactory)

Example 35 with TestSuiteChromosome

use of org.evosuite.testsuite.TestSuiteChromosome in project evosuite by EvoSuite.

the class CurrentTimeSystemTest method testCurrentTimeViaDateParameter.

@Test
public void testCurrentTimeViaDateParameter() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = CurrentTimeViaDateParameter.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.REPLACE_CALLS = true;
    // Properties.USE_DEPRECATED = false; // TODO why does the test pass only if USE_DEPRECATED is false???
    String[] command = new String[] { "-generateSuite", "-class", targetClass };
    Object result = evosuite.parseCommandLine(command);
    GeneticAlgorithm<?> ga = getGAFromResult(result);
    TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
    java.lang.System.out.println("Test Suite: " + best.toString());
    // 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);
}
Also used : EvoSuite(org.evosuite.EvoSuite) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) Test(org.junit.Test)

Aggregations

TestSuiteChromosome (org.evosuite.testsuite.TestSuiteChromosome)536 Test (org.junit.Test)430 EvoSuite (org.evosuite.EvoSuite)392 Properties (org.evosuite.Properties)78 OutputVariable (org.evosuite.statistics.OutputVariable)50 GenericSUTString (com.examples.with.different.packagename.generic.GenericSUTString)49 TestChromosome (org.evosuite.testcase.TestChromosome)47 BranchCoverageSuiteFitness (org.evosuite.coverage.branch.BranchCoverageSuiteFitness)44 TestCase (org.evosuite.testcase.TestCase)43 TestFitnessFunction (org.evosuite.testcase.TestFitnessFunction)30 DefaultTestCase (org.evosuite.testcase.DefaultTestCase)22 Ignore (org.junit.Ignore)19 ArrayList (java.util.ArrayList)17 DefaultLocalSearchObjective (org.evosuite.ga.localsearch.DefaultLocalSearchObjective)17 TestSuiteFitnessFunction (org.evosuite.testsuite.TestSuiteFitnessFunction)14 CheapPurityAnalyzer (org.evosuite.assertion.CheapPurityAnalyzer)13 LineCoverageSuiteFitness (org.evosuite.coverage.line.LineCoverageSuiteFitness)13 InstrumentingClassLoader (org.evosuite.instrumentation.InstrumentingClassLoader)13 ExecutionResult (org.evosuite.testcase.execution.ExecutionResult)10 Method (java.lang.reflect.Method)9