Search in sources :

Example 86 with TestChromosome

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

the class RegressionSuiteSerializer method getAppendedRegressionSuiteArchive.

/**
 * Get (and append) a coverage-based test suite archive for regression testing
 */
private static TestSuiteChromosome getAppendedRegressionSuiteArchive() {
    List<TestChromosome> previousArchive = TestSuiteSerialization.loadTests(REGRESSION_ARCHIVE_FILE);
    LoggingUtils.getEvoLogger().info("* previousArchive.size(): " + previousArchive.size());
    previousArchive.forEach(t -> t.getTestCase().removeAssertions());
    // execute previous regression test archive
    removeTestsThatDoNotcompile(previousArchive);
    Properties.TEST_ARCHIVE = false;
    TestSuiteChromosome archiveSuite = new TestSuiteChromosome();
    archiveSuite.addTests(previousArchive);
    BranchCoverageSuiteFitness branchCoverageSuiteFitness = new BranchCoverageSuiteFitness(TestGenerationContext.getInstance().getClassLoaderForSUT());
    // execute the test suite
    branchCoverageSuiteFitness.getFitness(archiveSuite);
    LoggingUtils.getEvoLogger().info("* archive covered goals: " + archiveSuite.getCoveredGoals().size());
    Properties.TEST_ARCHIVE = true;
    TestSuiteChromosome testArchive = Archive.getArchiveInstance().mergeArchiveAndSolution(archiveSuite);
    LoggingUtils.getEvoLogger().info("* newArchive.size(): " + testArchive.size());
    LoggingUtils.getEvoLogger().info("* new covered goals: " + testArchive.getCoveredGoals().size());
    // add all assertions
    AssertionStrategy tmpStrategy = Properties.ASSERTION_STRATEGY;
    Properties.ASSERTION_STRATEGY = AssertionStrategy.ALL;
    TestSuiteGeneratorHelper.addAssertions(testArchive);
    Properties.ASSERTION_STRATEGY = tmpStrategy;
    return testArchive;
}
Also used : BranchCoverageSuiteFitness(org.evosuite.coverage.branch.BranchCoverageSuiteFitness) TestChromosome(org.evosuite.testcase.TestChromosome) AssertionStrategy(org.evosuite.Properties.AssertionStrategy)

Example 87 with TestChromosome

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

the class RegressionSuiteSerializer method appendToRegressionTestSuite.

public static void appendToRegressionTestSuite(TestSuiteChromosome testSuite) {
    // load previous regression test suite
    List<TestChromosome> previousSuite = TestSuiteSerialization.loadTests(REGRESSION_FILE);
    LoggingUtils.getEvoLogger().info("* previousSuite.size(): " + previousSuite.size());
    // execute previous regression test chromosome
    removeTestsThatDoNotcompile(previousSuite);
    // write some statistics, e.g., number of failing test cases
    ClientServices.getInstance().getClientNode().trackOutputVariable(RuntimeVariable.NumRegressionTestCases, previousSuite.size());
    // join previous regression test suite with new test suite
    testSuite.addTests(previousSuite);
    // serialize
    TestSuiteSerialization.saveTests(testSuite, new File(REGRESSION_FILE));
}
Also used : TestChromosome(org.evosuite.testcase.TestChromosome) File(java.io.File)

Example 88 with TestChromosome

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

the class RegressionSuiteSerializer method removeTestsThatDoNotcompile.

private static void removeTestsThatDoNotcompile(List<TestChromosome> previousSuite) {
    // Store this value; if this option is true then the JUnit check
    // would not succeed, as the JUnit classloader wouldn't find the class
    boolean junitSeparateClassLoader = Properties.USE_SEPARATE_CLASSLOADER;
    Properties.USE_SEPARATE_CLASSLOADER = false;
    Iterator<TestChromosome> iterator = previousSuite.iterator();
    while (iterator.hasNext()) {
        TestCase tc = iterator.next().getTestCase();
        List<TestCase> testCases = new ArrayList<>();
        testCases.add(tc);
        JUnitAnalyzer.removeTestsThatDoNotCompile(testCases);
        if (testCases.isEmpty()) {
            // if TesCase 'tc' does not compile, just remove it
            iterator.remove();
        }
    }
    Properties.USE_SEPARATE_CLASSLOADER = junitSeparateClassLoader;
}
Also used : TestCase(org.evosuite.testcase.TestCase) ArrayList(java.util.ArrayList) TestChromosome(org.evosuite.testcase.TestChromosome)

Example 89 with TestChromosome

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

the class RelativeSuiteLengthBloatControl method iteration.

/**
 * {@inheritDoc}
 *
 * Set current max length to max of best chromosome
 */
@Override
public void iteration(GeneticAlgorithm<?> algorithm) {
    Chromosome best = algorithm.getBestIndividual();
    if (best instanceof TestSuiteChromosome)
        current_max = ((TestSuiteChromosome) best).totalLengthOfTestCases();
    if (best instanceof TestChromosome)
        current_max = ((TestChromosome) best).size();
    best_fitness = best.getFitness();
}
Also used : TestChromosome(org.evosuite.testcase.TestChromosome) Chromosome(org.evosuite.ga.Chromosome) TestChromosome(org.evosuite.testcase.TestChromosome)

Example 90 with TestChromosome

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

the class FixedSizeTestSuiteChromosomeFactory method getChromosome.

/* (non-Javadoc)
	 * @see org.evosuite.ga.ChromosomeFactory#getChromosome()
	 */
/**
 * {@inheritDoc}
 */
@Override
public TestSuiteChromosome getChromosome() {
    TestSuiteChromosome chromosome = new TestSuiteChromosome(new RandomLengthTestFactory());
    chromosome.clearTests();
    for (int i = 0; i < size; i++) {
        TestChromosome test = testChromosomeFactory.getChromosome();
        chromosome.addTest(test);
    }
    return chromosome;
}
Also used : TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) RandomLengthTestFactory(org.evosuite.testcase.factories.RandomLengthTestFactory) TestChromosome(org.evosuite.testcase.TestChromosome)

Aggregations

TestChromosome (org.evosuite.testcase.TestChromosome)128 TestSuiteChromosome (org.evosuite.testsuite.TestSuiteChromosome)47 ExecutionResult (org.evosuite.testcase.execution.ExecutionResult)33 TestFitnessFunction (org.evosuite.testcase.TestFitnessFunction)22 ArrayList (java.util.ArrayList)17 TestCase (org.evosuite.testcase.TestCase)17 DefaultTestCase (org.evosuite.testcase.DefaultTestCase)16 HashSet (java.util.HashSet)15 Properties (org.evosuite.Properties)15 Test (org.junit.Test)15 BranchCoverageSuiteFitness (org.evosuite.coverage.branch.BranchCoverageSuiteFitness)14 HashMap (java.util.HashMap)11 DefaultLocalSearchObjective (org.evosuite.ga.localsearch.DefaultLocalSearchObjective)10 AbstractTestSuiteChromosome (org.evosuite.testsuite.AbstractTestSuiteChromosome)8 LinkedHashMap (java.util.LinkedHashMap)7 Foo (com.examples.with.different.packagename.symbolic.Foo)6 LinkedHashSet (java.util.LinkedHashSet)6 Set (java.util.Set)6 TestSuiteFitnessFunction (org.evosuite.testsuite.TestSuiteFitnessFunction)6 Map (java.util.Map)5