Search in sources :

Example 11 with EvoSuite

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

the class MethodCoverageFitnessFunctionSystemTest method systemTestMethodCoverageInnerClasses.

@Test
public void systemTestMethodCoverageInnerClasses() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = ClassWithInnerClass.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 = TestGenerationStrategy.getFitnessFactories().get(0).getCoverageGoals().size();
    Assert.assertEquals(4, goals);
    System.out.println("EvolvedTestSuite:\n" + best);
    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)

Example 12 with EvoSuite

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

the class MethodTraceCoverageFitnessFunctionSystemTest method testMethodFitnessCompositionalExample.

public void testMethodFitnessCompositionalExample() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = Compositional.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(4, goals);
    Assert.assertEquals("Non-optimal coverage: ", 1d, best.getCoverage(), 0.001);
}
Also used : EvoSuite(org.evosuite.EvoSuite) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome)

Example 13 with EvoSuite

use of org.evosuite.EvoSuite 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 14 with EvoSuite

use of org.evosuite.EvoSuite 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 15 with EvoSuite

use of org.evosuite.EvoSuite 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)

Aggregations

EvoSuite (org.evosuite.EvoSuite)462 Test (org.junit.Test)410 TestSuiteChromosome (org.evosuite.testsuite.TestSuiteChromosome)391 Properties (org.evosuite.Properties)86 OutputVariable (org.evosuite.statistics.OutputVariable)61 GenericSUTString (com.examples.with.different.packagename.generic.GenericSUTString)49 SearchStatistics (org.evosuite.statistics.SearchStatistics)16 Ignore (org.junit.Ignore)15 CheapPurityAnalyzer (org.evosuite.assertion.CheapPurityAnalyzer)13 CSVReader (com.opencsv.CSVReader)12 FileReader (java.io.FileReader)12 File (java.io.File)9 TestCase (org.evosuite.testcase.TestCase)8 ArrayList (java.util.ArrayList)7 List (java.util.List)7 MethodCoverageFitnessFunctionSystemTest (org.evosuite.coverage.method.MethodCoverageFitnessFunctionSystemTest)7 Before (org.junit.Before)7 TypeSeedingExampleString (com.examples.with.different.packagename.TypeSeedingExampleString)6 TestGenerationResult (org.evosuite.result.TestGenerationResult)6 CalculatorTest (com.examples.with.different.packagename.CalculatorTest)5