Search in sources :

Example 1 with TestSuiteLocalSearchObjective

use of org.evosuite.testsuite.localsearch.TestSuiteLocalSearchObjective in project evosuite by EvoSuite.

the class TestDSETestCaseLocalSearch 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 = 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);
    DefaultTestCase duplicatedTestCase0 = buildTestCase0();
    TestChromosome duplicatedTestChromosome0 = new TestChromosome();
    duplicatedTestChromosome0.setTestCase(duplicatedTestCase0);
    suite.addTest(duplicatedTestChromosome0);
    TestSuiteLocalSearchObjective localSearchObjective = TestSuiteLocalSearchObjective.buildNewTestSuiteLocalSearchObjective(Collections.singletonList(branchCoverageSuiteFitness), suite, 1);
    DSETestCaseLocalSearch localSearch = new DSETestCaseLocalSearch();
    boolean improved = localSearch.doSearch(duplicatedTestChromosome0, localSearchObjective);
    assertTrue(improved);
    double fitnessAfterLocalSearch = branchCoverageSuiteFitness.getFitness(suite);
    int coveredGoalsAfterLocalSearch = suite.getNumOfCoveredGoals();
    assertTrue(fitnessAfterLocalSearch < fitnessBeforeLocalSearch);
    assertTrue(coveredGoalsAfterLocalSearch > coveredGoalsBeforeLocalSearch);
}
Also used : TestSuiteLocalSearchObjective(org.evosuite.testsuite.localsearch.TestSuiteLocalSearchObjective) 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 2 with TestSuiteLocalSearchObjective

use of org.evosuite.testsuite.localsearch.TestSuiteLocalSearchObjective in project evosuite by EvoSuite.

the class TestDSETestCaseLocalSearch 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);
    DefaultTestCase duplicatedTestCase0 = buildTestCase0();
    TestChromosome duplicatedTestChromosome0 = new TestChromosome();
    duplicatedTestChromosome0.setTestCase(duplicatedTestCase0);
    suite.addTest(duplicatedTestChromosome0);
    TestSuiteLocalSearchObjective localSearchObjective = TestSuiteLocalSearchObjective.buildNewTestSuiteLocalSearchObjective(Collections.singletonList(branchCoverageSuiteFitness), suite, 1);
    DSETestCaseLocalSearch localSearch = new DSETestCaseLocalSearch();
    boolean improved = localSearch.doSearch(duplicatedTestChromosome0, localSearchObjective);
    assertTrue(improved);
    double fitnessAfterLocalSearch = branchCoverageSuiteFitness.getFitness(suite);
    int coveredGoalsAfterLocalSearch = suite.getNumOfCoveredGoals();
    assertTrue(fitnessAfterLocalSearch < fitnessBeforeLocalSearch);
    assertTrue(coveredGoalsAfterLocalSearch > coveredGoalsBeforeLocalSearch);
}
Also used : TestSuiteLocalSearchObjective(org.evosuite.testsuite.localsearch.TestSuiteLocalSearchObjective) 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)

Aggregations

Foo (com.examples.with.different.packagename.symbolic.Foo)2 Properties (org.evosuite.Properties)2 BranchCoverageSuiteFitness (org.evosuite.coverage.branch.BranchCoverageSuiteFitness)2 DefaultTestCase (org.evosuite.testcase.DefaultTestCase)2 TestChromosome (org.evosuite.testcase.TestChromosome)2 TestSuiteChromosome (org.evosuite.testsuite.TestSuiteChromosome)2 TestSuiteLocalSearchObjective (org.evosuite.testsuite.localsearch.TestSuiteLocalSearchObjective)2 Test (org.junit.Test)2