Search in sources :

Example 16 with TestSuiteChromosome

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

the class TestDSETestSuiteFoo method testAVMSolver.

@Test
public void testAVMSolver() throws NoSuchMethodException, SecurityException, ClassNotFoundException {
    Properties.DSE_SOLVER = Properties.SolverType.EVOSUITE_SOLVER;
    Properties.CRITERION = new Properties.Criterion[] { Criterion.BRANCH };
    Properties.TARGET_CLASS = Foo.class.getName();
    TestGenerationContext.getInstance().getClassLoaderForSUT().loadClass(Properties.TARGET_CLASS);
    BranchCoverageSuiteFitness branchCoverageSuiteFitness = new BranchCoverageSuiteFitness();
    TestSuiteChromosome suite = new TestSuiteChromosome();
    suite.addFitness(branchCoverageSuiteFitness);
    branchCoverageSuiteFitness.getFitness(suite);
    // no goals covered yet
    int coveredGoals0 = suite.getNumOfCoveredGoals();
    int notCoveredGoals0 = suite.getNumOfNotCoveredGoals();
    assertEquals(0, coveredGoals0);
    assertNotEquals(0, notCoveredGoals0);
    DefaultTestCase testCase0 = buildTestCase0();
    TestChromosome testChromosome0 = new TestChromosome();
    testChromosome0.setTestCase(testCase0);
    suite.addTest(testChromosome0);
    double fitnessBeforeLocalSearch = branchCoverageSuiteFitness.getFitness(suite);
    int coveredGoalsBeforeLocalSearch = suite.getNumOfCoveredGoals();
    // some goal was covered
    assertTrue(coveredGoalsBeforeLocalSearch > 0);
    LocalSearchObjective<TestSuiteChromosome> localSearchObjective = new DefaultLocalSearchObjective<>();
    localSearchObjective.addFitnessFunction(branchCoverageSuiteFitness);
    TestSuiteLocalSearch localSearch = new TestSuiteLocalSearch();
    boolean improved;
    do {
        improved = localSearch.doSearch(suite, localSearchObjective);
    } while (improved);
    double fitnessAfterLocalSearch = branchCoverageSuiteFitness.getFitness(suite);
    int coveredGoalsAfterLocalSearch = suite.getNumOfCoveredGoals();
    assertTrue(fitnessAfterLocalSearch < fitnessBeforeLocalSearch);
    assertTrue(coveredGoalsAfterLocalSearch > coveredGoalsBeforeLocalSearch);
    int finalSuiteSize = suite.size();
    assertTrue(coveredGoalsAfterLocalSearch >= 7);
    assertTrue(finalSuiteSize >= 4);
}
Also used : DefaultLocalSearchObjective(org.evosuite.ga.localsearch.DefaultLocalSearchObjective) Foo(com.examples.with.different.packagename.symbolic.Foo) BranchCoverageSuiteFitness(org.evosuite.coverage.branch.BranchCoverageSuiteFitness) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) Properties(org.evosuite.Properties) TestChromosome(org.evosuite.testcase.TestChromosome) Test(org.junit.Test)

Example 17 with TestSuiteChromosome

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

the class TestDSETestSuiteTriangle method testCVC4Solver.

@Test
public void testCVC4Solver() throws NoSuchMethodException, SecurityException, ClassNotFoundException {
    String cvc4_path = System.getenv("cvc4_path");
    if (cvc4_path != null) {
        Properties.CVC4_PATH = cvc4_path;
    }
    Assume.assumeTrue(Properties.CVC4_PATH != null);
    Properties.DSE_SOLVER = Properties.SolverType.CVC4_SOLVER;
    Properties.CRITERION = new Properties.Criterion[] { Criterion.BRANCH };
    Properties.TARGET_CLASS = Triangle.class.getName();
    TestGenerationContext.getInstance().getClassLoaderForSUT().loadClass(Properties.TARGET_CLASS);
    BranchCoverageSuiteFitness branchCoverageSuiteFitness = new BranchCoverageSuiteFitness();
    TestSuiteChromosome suite = new TestSuiteChromosome();
    suite.addFitness(branchCoverageSuiteFitness);
    branchCoverageSuiteFitness.getFitness(suite);
    // no goals covered yet
    int coveredGoals0 = suite.getNumOfCoveredGoals();
    int notCoveredGoals0 = suite.getNumOfNotCoveredGoals();
    assertEquals(0, coveredGoals0);
    assertNotEquals(0, notCoveredGoals0);
    DefaultTestCase testCase0 = buildTestCase0();
    TestChromosome testChromosome0 = new TestChromosome();
    testChromosome0.setTestCase(testCase0);
    suite.addTest(testChromosome0);
    double fitnessBeforeLocalSearch = branchCoverageSuiteFitness.getFitness(suite);
    int coveredGoalsBeforeLocalSearch = suite.getNumOfCoveredGoals();
    // some goal was covered
    assertTrue(coveredGoalsBeforeLocalSearch > 0);
    LocalSearchObjective<TestSuiteChromosome> localSearchObjective = new DefaultLocalSearchObjective<>();
    localSearchObjective.addFitnessFunction(branchCoverageSuiteFitness);
    boolean improved;
    do {
        TestSuiteLocalSearch localSearch = new TestSuiteLocalSearch();
        improved = localSearch.doSearch(suite, localSearchObjective);
    } while (improved);
    double fitnessAfterLocalSearch = branchCoverageSuiteFitness.getFitness(suite);
    int coveredGoalsAfterLocalSearch = suite.getNumOfCoveredGoals();
    assertTrue(fitnessAfterLocalSearch < fitnessBeforeLocalSearch);
    assertTrue(coveredGoalsAfterLocalSearch > coveredGoalsBeforeLocalSearch);
    int finalSuiteSize = suite.size();
    assertEquals(18, coveredGoalsAfterLocalSearch);
    assertTrue(finalSuiteSize > 1);
}
Also used : BranchCoverageSuiteFitness(org.evosuite.coverage.branch.BranchCoverageSuiteFitness) Triangle(com.examples.with.different.packagename.ncs.Triangle) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) Properties(org.evosuite.Properties) DefaultLocalSearchObjective(org.evosuite.ga.localsearch.DefaultLocalSearchObjective) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) TestChromosome(org.evosuite.testcase.TestChromosome) Test(org.junit.Test)

Example 18 with TestSuiteChromosome

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

the class TestDSETestSuiteTriangle method testAVMSolver.

@Test
public void testAVMSolver() throws NoSuchMethodException, SecurityException, ClassNotFoundException {
    Properties.DSE_SOLVER = Properties.SolverType.EVOSUITE_SOLVER;
    Properties.CRITERION = new Properties.Criterion[] { Criterion.BRANCH };
    Properties.TARGET_CLASS = Triangle.class.getName();
    TestGenerationContext.getInstance().getClassLoaderForSUT().loadClass(Properties.TARGET_CLASS);
    BranchCoverageSuiteFitness branchCoverageSuiteFitness = new BranchCoverageSuiteFitness();
    TestSuiteChromosome suite = new TestSuiteChromosome();
    suite.addFitness(branchCoverageSuiteFitness);
    branchCoverageSuiteFitness.getFitness(suite);
    // no goals covered yet
    int coveredGoals0 = suite.getNumOfCoveredGoals();
    int notCoveredGoals0 = suite.getNumOfNotCoveredGoals();
    assertEquals(0, coveredGoals0);
    assertNotEquals(0, notCoveredGoals0);
    DefaultTestCase testCase0 = buildTestCase0();
    TestChromosome testChromosome0 = new TestChromosome();
    testChromosome0.setTestCase(testCase0);
    suite.addTest(testChromosome0);
    double fitnessBeforeLocalSearch = branchCoverageSuiteFitness.getFitness(suite);
    int coveredGoalsBeforeLocalSearch = suite.getNumOfCoveredGoals();
    // some goal was covered
    assertTrue(coveredGoalsBeforeLocalSearch > 0);
    LocalSearchObjective<TestSuiteChromosome> localSearchObjective = new DefaultLocalSearchObjective<>();
    localSearchObjective.addFitnessFunction(branchCoverageSuiteFitness);
    boolean improved;
    do {
        TestSuiteLocalSearch localSearch = new TestSuiteLocalSearch();
        improved = localSearch.doSearch(suite, localSearchObjective);
    } while (improved);
    double fitnessAfterLocalSearch = branchCoverageSuiteFitness.getFitness(suite);
    int coveredGoalsAfterLocalSearch = suite.getNumOfCoveredGoals();
    assertTrue(fitnessAfterLocalSearch < fitnessBeforeLocalSearch);
    assertTrue(coveredGoalsAfterLocalSearch > coveredGoalsBeforeLocalSearch);
    int finalSuiteSize = suite.size();
    assertTrue(coveredGoalsAfterLocalSearch > coveredGoalsBeforeLocalSearch);
    assertTrue(finalSuiteSize >= 2);
}
Also used : DefaultLocalSearchObjective(org.evosuite.ga.localsearch.DefaultLocalSearchObjective) BranchCoverageSuiteFitness(org.evosuite.coverage.branch.BranchCoverageSuiteFitness) Triangle(com.examples.with.different.packagename.ncs.Triangle) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) Properties(org.evosuite.Properties) TestChromosome(org.evosuite.testcase.TestChromosome) Test(org.junit.Test)

Example 19 with TestSuiteChromosome

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

the class TestDSETestSuiteFlag method testCVC4Solver.

@Test
public void testCVC4Solver() throws NoSuchMethodException, SecurityException, ClassNotFoundException {
    String cvc4_path = System.getenv("cvc4_path");
    if (cvc4_path != null) {
        Properties.CVC4_PATH = cvc4_path;
    }
    Assume.assumeTrue(Properties.CVC4_PATH != null);
    Properties.DSE_SOLVER = Properties.SolverType.CVC4_SOLVER;
    Properties.CRITERION = new Properties.Criterion[] { Criterion.BRANCH };
    Properties.TARGET_CLASS = Flag.class.getName();
    TestGenerationContext.getInstance().getClassLoaderForSUT().loadClass(Properties.TARGET_CLASS);
    BranchCoverageSuiteFitness branchCoverageSuiteFitness = new BranchCoverageSuiteFitness();
    TestSuiteChromosome suite = new TestSuiteChromosome();
    suite.addFitness(branchCoverageSuiteFitness);
    branchCoverageSuiteFitness.getFitness(suite);
    // no goals covered yet
    int coveredGoals0 = suite.getNumOfCoveredGoals();
    int notCoveredGoals0 = suite.getNumOfNotCoveredGoals();
    assertEquals(0, coveredGoals0);
    assertNotEquals(0, notCoveredGoals0);
    DefaultTestCase testCase0 = buildTestCase0();
    TestChromosome testChromosome0 = new TestChromosome();
    testChromosome0.setTestCase(testCase0);
    suite.addTest(testChromosome0);
    branchCoverageSuiteFitness.getFitness(suite);
    DefaultTestCase testCase1 = buildTestCase1();
    TestChromosome testChromosome1 = new TestChromosome();
    testChromosome1.setTestCase(testCase1);
    suite.addTest(testChromosome1);
    double fitnessBeforeLocalSearch = branchCoverageSuiteFitness.getFitness(suite);
    int coveredGoalsBeforeLocalSearch = suite.getNumOfCoveredGoals();
    // some goal was covered
    assertTrue(coveredGoalsBeforeLocalSearch > 0);
    LocalSearchObjective<TestSuiteChromosome> localSearchObjective = new DefaultLocalSearchObjective<>();
    localSearchObjective.addFitnessFunction(branchCoverageSuiteFitness);
    boolean improved;
    do {
        TestSuiteLocalSearch localSearch = new TestSuiteLocalSearch();
        improved = localSearch.doSearch(suite, localSearchObjective);
    } while (improved);
    double fitnessAfterLocalSearch = branchCoverageSuiteFitness.getFitness(suite);
    int coveredGoalsAfterLocalSearch = suite.getNumOfCoveredGoals();
    assertTrue(fitnessAfterLocalSearch < fitnessBeforeLocalSearch);
    assertTrue(coveredGoalsAfterLocalSearch > coveredGoalsBeforeLocalSearch);
    int finalSuiteSize = suite.size();
    /*
		 * Check at least 6 goals were covered
		 */
    assertTrue(coveredGoalsAfterLocalSearch >= 6);
    assertTrue(finalSuiteSize > 1);
}
Also used : BranchCoverageSuiteFitness(org.evosuite.coverage.branch.BranchCoverageSuiteFitness) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) Properties(org.evosuite.Properties) Flag(com.examples.with.different.packagename.ncs.Flag) DefaultLocalSearchObjective(org.evosuite.ga.localsearch.DefaultLocalSearchObjective) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) TestChromosome(org.evosuite.testcase.TestChromosome) Test(org.junit.Test)

Example 20 with TestSuiteChromosome

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

the class RandomIndividualTestSuiteChromosomeFactorySystemTest method testRandomSeed.

@Test
public void testRandomSeed() {
    Properties.SEED_PROBABILITY = 1;
    RandomIndividualTestSuiteChromosomeFactory bicf = new RandomIndividualTestSuiteChromosomeFactory(defaultFactory, ga);
    bicf.getChromosome();
    boolean isFromPopulation = false;
    TestSuiteChromosome tsc = bicf.getChromosome();
    for (TestSuiteChromosome t : ga.getPopulation()) {
        if (tsc.equals(t)) {
            isFromPopulation = true;
        }
    }
    assertTrue(isFromPopulation);
}
Also used : 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