use of org.evosuite.EvoSuite in project evosuite by EvoSuite.
the class AbstractErrorBranchTest method runEvoSuite.
private TestSuiteChromosome runEvoSuite(Class<?> targetClass) {
EvoSuite evosuite = new EvoSuite();
String targetClassName = targetClass.getCanonicalName();
Properties.TARGET_CLASS = targetClassName;
Properties.ASSERTIONS = false;
Properties.JUNIT_TESTS = false;
Properties.JUNIT_CHECK = false;
Properties.CRITERION = new Properties.Criterion[] { Properties.Criterion.BRANCH, Properties.Criterion.TRYCATCH };
String[] command = new String[] { "-generateSuite", "-class", targetClassName };
StringBuilder s = new StringBuilder();
s.append(RuntimeVariable.Coverage);
s.append(",");
s.append(RuntimeVariable.BranchCoverage);
s.append(",");
s.append(RuntimeVariable.Covered_Goals);
s.append(",");
s.append(RuntimeVariable.Total_Goals);
s.append(",");
s.append(RuntimeVariable.Covered_Branches);
s.append(",");
s.append(RuntimeVariable.Covered_Branchless_Methods);
s.append(",");
s.append(RuntimeVariable.Covered_Branches_Real);
s.append(",");
s.append(RuntimeVariable.Covered_Branches_Instrumented);
s.append(",");
Properties.OUTPUT_VARIABLES = s.toString();
Object result = evosuite.parseCommandLine(command);
GeneticAlgorithm<?> ga = getGAFromResult(result);
TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
System.out.println(best.toString());
return best;
}
use of org.evosuite.EvoSuite in project evosuite by EvoSuite.
the class ContainerTransformationSystemTest method testIntegerList.
@Test
public void testIntegerList() {
EvoSuite evosuite = new EvoSuite();
String targetClass = IntegerContainerBranch.class.getCanonicalName();
Properties.TARGET_CLASS = targetClass;
Properties.SEARCH_BUDGET = 80000;
String[] command = new String[] { "-generateSuite", "-class", targetClass };
Object result = evosuite.parseCommandLine(command);
Assert.assertTrue(result != null);
GeneticAlgorithm<?> ga = getGAFromResult(result);
TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
System.out.println("EvolvedTestSuite:\n" + best);
// assuming single fitness function
int goals = TestGenerationStrategy.getFitnessFactories().get(0).getCoverageGoals().size();
Assert.assertEquals("Wrong number of goals: ", 5, goals);
Assert.assertEquals("Non-optimal coverage: ", 1d, best.getCoverage(), 0.001);
}
use of org.evosuite.EvoSuite in project evosuite by EvoSuite.
the class ContainerTransformationSystemTest method testIntegerListList.
@Test
public void testIntegerListList() {
EvoSuite evosuite = new EvoSuite();
String targetClass = IntegerCollectionAllBranch.class.getCanonicalName();
Properties.TARGET_CLASS = targetClass;
Properties.SEARCH_BUDGET = 180000;
String[] command = new String[] { "-generateSuite", "-class", targetClass };
Object result = evosuite.parseCommandLine(command);
Assert.assertTrue(result != null);
GeneticAlgorithm<?> ga = getGAFromResult(result);
TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
System.out.println("EvolvedTestSuite:\n" + best);
// assuming single fitness function
int goals = TestGenerationStrategy.getFitnessFactories().get(0).getCoverageGoals().size();
Assert.assertEquals("Wrong number of goals: ", 5, goals);
Assert.assertEquals("Non-optimal coverage: ", 1d, best.getCoverage(), 0.001);
}
use of org.evosuite.EvoSuite in project evosuite by EvoSuite.
the class TP1SystemTest method testLocalSearch.
@Test
public void testLocalSearch() {
Properties.MINIMIZATION_TIMEOUT = 10;
Properties.LOCAL_SEARCH_BUDGET = 100;
Properties.LOCAL_SEARCH_BUDGET_TYPE = Properties.LocalSearchBudgetType.TESTS;
EvoSuite evosuite = new EvoSuite();
String targetClass = TP1.class.getCanonicalName();
Properties.TARGET_CLASS = targetClass;
// force using only LS, no DSE
Properties.DSE_PROBABILITY = 0.0;
Properties.CRITERION = new Criterion[] { // these are basic criteria that should be always on by default
Criterion.LINE, Criterion.BRANCH, Criterion.EXCEPTION, Criterion.WEAKMUTATION, Criterion.OUTPUT, Criterion.METHOD, Criterion.METHODNOEXCEPTION, Criterion.CBRANCH };
String[] command = new String[] { "-generateSuite", "-class", targetClass };
Object result = evosuite.parseCommandLine(command);
GeneticAlgorithm<?> ga = getGAFromResult(result);
TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
System.out.println("EvolvedTestSuite:\n" + best);
}
use of org.evosuite.EvoSuite in project evosuite by EvoSuite.
the class TP1SystemTest method testZ3.
@Test
public void testZ3() {
Assume.assumeTrue(System.getenv("z3_path") != null);
Properties.Z3_PATH = System.getenv("z3_path");
Properties.LOCAL_SEARCH_BUDGET_TYPE = Properties.LocalSearchBudgetType.TIME;
Properties.LOCAL_SEARCH_BUDGET = 5;
EvoSuite evosuite = new EvoSuite();
String targetClass = TP1.class.getCanonicalName();
Properties.TARGET_CLASS = targetClass;
Properties.DSE_SOLVER = Properties.SolverType.Z3_SOLVER;
// force using only LS, no DSE
Properties.DSE_PROBABILITY = 1.0;
Properties.CRITERION = new Criterion[] { // these are basic criteria that should be always on by default
Criterion.LINE, Criterion.BRANCH, Criterion.EXCEPTION, Criterion.WEAKMUTATION, Criterion.OUTPUT, Criterion.METHOD, Criterion.METHODNOEXCEPTION, Criterion.CBRANCH };
String[] command = new String[] { "-generateSuite", "-class", targetClass };
Object result = evosuite.parseCommandLine(command);
GeneticAlgorithm<?> ga = getGAFromResult(result);
TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
System.out.println("EvolvedTestSuite:\n" + best);
}
Aggregations