Search in sources :

Example 51 with EvoSuite

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;
}
Also used : EvoSuite(org.evosuite.EvoSuite) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) Properties(org.evosuite.Properties)

Example 52 with EvoSuite

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);
}
Also used : EvoSuite(org.evosuite.EvoSuite) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) Test(org.junit.Test)

Example 53 with EvoSuite

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);
}
Also used : EvoSuite(org.evosuite.EvoSuite) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) Test(org.junit.Test)

Example 54 with EvoSuite

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);
}
Also used : EvoSuite(org.evosuite.EvoSuite) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) Test(org.junit.Test)

Example 55 with EvoSuite

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);
}
Also used : EvoSuite(org.evosuite.EvoSuite) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) Test(org.junit.Test)

Aggregations

EvoSuite (org.evosuite.EvoSuite)462 Test (org.junit.Test)410 TestSuiteChromosome (org.evosuite.testsuite.TestSuiteChromosome)391 Properties (org.evosuite.Properties)86 OutputVariable (org.evosuite.statistics.OutputVariable)61 GenericSUTString (com.examples.with.different.packagename.generic.GenericSUTString)49 SearchStatistics (org.evosuite.statistics.SearchStatistics)16 Ignore (org.junit.Ignore)15 CheapPurityAnalyzer (org.evosuite.assertion.CheapPurityAnalyzer)13 CSVReader (com.opencsv.CSVReader)12 FileReader (java.io.FileReader)12 File (java.io.File)9 TestCase (org.evosuite.testcase.TestCase)8 ArrayList (java.util.ArrayList)7 List (java.util.List)7 MethodCoverageFitnessFunctionSystemTest (org.evosuite.coverage.method.MethodCoverageFitnessFunctionSystemTest)7 Before (org.junit.Before)7 TypeSeedingExampleString (com.examples.with.different.packagename.TypeSeedingExampleString)6 TestGenerationResult (org.evosuite.result.TestGenerationResult)6 CalculatorTest (com.examples.with.different.packagename.CalculatorTest)5