use of org.evosuite.testcase.TestCase in project evosuite by EvoSuite.
the class BIMutatedMethodSeedingTestSuiteChromosomeFactorySystemTest method testBIMutatedMethod.
@Test
public void testBIMutatedMethod() {
// probability is SEED_PROBABILITY/test cases, so 10 guarentees a seed
Properties.SEED_PROBABILITY = 10;
// Test requires configured test cluster otherwise
Properties.SEED_MUTATIONS = 0;
BIMutatedMethodSeedingTestSuiteChromosomeFactory factory = new BIMutatedMethodSeedingTestSuiteChromosomeFactory(defaultFactory, bestIndividual);
TestSuiteChromosome chromosome = factory.getChromosome();
boolean containsMutatedSeededMethod = false;
for (TestCase t : chromosome.getTests()) {
for (TestCase t2 : bestIndividual.getTests()) {
if (!t.equals(t2) && !t.equals(TestSampleFactory.CHROMOSOME)) {
// test case not from original BI or from sample factory,
// so must be seeded mutated BI
containsMutatedSeededMethod = true;
}
}
}
assertTrue(containsMutatedSeededMethod);
}
use of org.evosuite.testcase.TestCase in project evosuite by EvoSuite.
the class LocalSearchNumericSystemTest method runDoubleExample.
private void runDoubleExample(double x, double y) throws ClassNotFoundException, ConstructionFailedException, NoSuchMethodException, SecurityException {
TestCase test = getDoubleTest(x, y);
TestSuiteChromosome suite = new TestSuiteChromosome();
BranchCoverageSuiteFitness fitness = new BranchCoverageSuiteFitness();
BranchCoverageMap.getInstance().searchStarted(null);
assertEquals(4.0, fitness.getFitness(suite), 0.1F);
suite.addTest(test);
assertEquals(1.0, fitness.getFitness(suite), 0.1F);
TestSuiteLocalSearch localSearch = TestSuiteLocalSearch.selectTestSuiteLocalSearch();
LocalSearchObjective<TestSuiteChromosome> localObjective = new DefaultLocalSearchObjective<TestSuiteChromosome>();
localObjective.addFitnessFunction(fitness);
localSearch.doSearch(suite, localObjective);
System.out.println("Fitness: " + fitness.getFitness(suite));
System.out.println("Test suite: " + suite);
assertEquals(0.0, fitness.getFitness(suite), 0.1F);
BranchCoverageMap.getInstance().searchFinished(null);
}
use of org.evosuite.testcase.TestCase in project evosuite by EvoSuite.
the class RandomMethodSeedingTestSuiteChromosomeFactorySystemTest method testRandomMethod.
@Test
public void testRandomMethod() {
// probability is SEED_PROBABILITY/test cases, so 10 guarentees a seed
Properties.SEED_PROBABILITY = 10;
RandomMethodSeedingTestSuiteChromosomeFactory factory = new RandomMethodSeedingTestSuiteChromosomeFactory(defaultFactory, ga);
TestSuiteChromosome chromosome = factory.getChromosome();
boolean containsSeededMethod = false;
for (TestCase t : chromosome.getTests()) {
for (TestSuiteChromosome tsc : ga.getPopulation()) {
for (TestCase t2 : tsc.getTests()) {
if (t.equals(t2)) {
containsSeededMethod = true;
}
}
}
}
assertTrue(containsSeededMethod);
}
use of org.evosuite.testcase.TestCase in project evosuite by EvoSuite.
the class LIPS method runTest.
/**
* This method executes a given test case (i.e., TestChromosome)
*
* @param c test case (TestChromosome) to execute
*/
protected void runTest(T c) {
if (!c.isChanged())
return;
// run the test
TestCase test = ((TestChromosome) c).getTestCase();
ExecutionResult result = TestCaseExecutor.runTest(test);
((TestChromosome) c).setLastExecutionResult(result);
c.setChanged(false);
// notify the fitness evaluation (i.e., the test is executed)
notifyEvaluation(c);
}
use of org.evosuite.testcase.TestCase in project evosuite by EvoSuite.
the class BranchesManager method calculateFitness.
public void calculateFitness(T c) {
// run the test
TestCase test = ((TestChromosome) c).getTestCase();
ExecutionResult result = TestCaseExecutor.runTest(test);
((TestChromosome) c).setLastExecutionResult(result);
c.setChanged(false);
if (result.hasTimeout() || result.hasTestException()) {
for (FitnessFunction<T> f : currentGoals) c.setFitness(f, Double.MAX_VALUE);
return;
}
// 1) we update the set of currents goals
Set<FitnessFunction<T>> visitedStatements = new HashSet<FitnessFunction<T>>(uncoveredGoals.size() * 2);
LinkedList<FitnessFunction<T>> targets = new LinkedList<FitnessFunction<T>>();
targets.addAll(this.currentGoals);
while (targets.size() > 0) {
FitnessFunction<T> fitnessFunction = targets.poll();
int past_size = visitedStatements.size();
visitedStatements.add(fitnessFunction);
if (past_size == visitedStatements.size())
continue;
double value = fitnessFunction.getFitness(c);
if (value == 0.0) {
updateCoveredGoals(fitnessFunction, c);
for (FitnessFunction<T> child : graph.getStructuralChildren(fitnessFunction)) {
targets.addLast(child);
}
} else {
currentGoals.add(fitnessFunction);
}
}
currentGoals.removeAll(coveredGoals.keySet());
// 2) we update the archive
for (Integer branchid : result.getTrace().getCoveredFalseBranches()) {
FitnessFunction<T> branch = this.branchCoverageFalseMap.get(branchid);
if (branch == null)
continue;
updateCoveredGoals((FitnessFunction<T>) branch, c);
}
for (Integer branchid : result.getTrace().getCoveredTrueBranches()) {
FitnessFunction<T> branch = this.branchCoverageTrueMap.get(branchid);
if (branch == null)
continue;
updateCoveredGoals((FitnessFunction<T>) branch, c);
}
for (String method : result.getTrace().getCoveredBranchlessMethods()) {
FitnessFunction<T> branch = this.branchlessMethodCoverageMap.get(method);
if (branch == null)
continue;
updateCoveredGoals((FitnessFunction<T>) branch, c);
}
// debugStructuralDependencies(c);
}
Aggregations