use of org.evosuite.strategy.PropertiesTestGAFactory in project evosuite by EvoSuite.
the class TestCaseReplacer method replaceTest.
/**
* Given a test, create a GA and look for a replacement test
*
* @param test
*/
public TestCase replaceTest(String targetClass, List<TestCase> otherTests, TestCase test) {
// Various environmental setup necessary for EvoSuite
Properties.ALGORITHM = Algorithm.MONOTONICGA;
Properties.STRATEGY = Strategy.ONEBRANCH;
ExecutionTracer.enableTraceCalls();
// Run for 10 generations - adapt as necessary
// Properties.STOPPING_CONDITION = StoppingCondition.MAXGENERATIONS;
// Properties.SEARCH_BUDGET = 20;
// Properties.STOPPING_CONDITION = StoppingCondition.MAXTIME;
// Properties.SEARCH_BUDGET = 20;
// GeneticAlgorithm ga = TestSuiteGenerator.getGeneticAlgorithm(new RandomLengthTestFactory());
// TODO: JM: Needs Testing. Not sure if this is equivalent:
PropertiesTestGAFactory algorithmFactory = new PropertiesTestGAFactory();
GeneticAlgorithm<TestChromosome> ga = algorithmFactory.getSearchAlgorithm();
List<TestFitnessFactory<? extends TestFitnessFunction>> factories = TestSuiteGenerator.getFitnessFactories();
Collection<TestFitnessFunction> fitnessFunctions = new ArrayList<TestFitnessFunction>();
for (TestFitnessFactory<? extends TestFitnessFunction> factory : factories) {
// Set up fitness function for the parsed test case
DifferenceFitnessFunction fitnessFunction = new DifferenceFitnessFunction(test, otherTests, factory);
// ga.setFitnessFunction(fitness);
fitnessFunctions.add(fitnessFunction);
ga.addFitnessFunction(fitnessFunction);
}
// Perform calculation
ga.generateSolution();
// The best individual at the end of the search contains our candidate solution
TestChromosome testChromosome = (TestChromosome) ga.getBestIndividual();
TestCaseMinimizer minimizer = new TestCaseMinimizer(fitnessFunctions);
minimizer.minimize(testChromosome);
System.out.println("Best individual has fitness: " + testChromosome.getFitness());
return testChromosome.getTestCase();
}
Aggregations