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;
}
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));
}
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;
}
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();
}
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;
}
Aggregations