Search in sources :

Example 66 with TestSuiteChromosome

use of org.evosuite.testsuite.TestSuiteChromosome 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 67 with TestSuiteChromosome

use of org.evosuite.testsuite.TestSuiteChromosome 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 68 with TestSuiteChromosome

use of org.evosuite.testsuite.TestSuiteChromosome 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 69 with TestSuiteChromosome

use of org.evosuite.testsuite.TestSuiteChromosome 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)

Example 70 with TestSuiteChromosome

use of org.evosuite.testsuite.TestSuiteChromosome in project evosuite by EvoSuite.

the class MockFileSystemTest method testCreateNewTmpFile.

@Test
public void testCreateNewTmpFile() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = CreateNewTmpFile.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.SEARCH_BUDGET = 20000;
    Properties.VIRTUAL_FS = true;
    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: ", 3, 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)

Aggregations

TestSuiteChromosome (org.evosuite.testsuite.TestSuiteChromosome)536 Test (org.junit.Test)430 EvoSuite (org.evosuite.EvoSuite)392 Properties (org.evosuite.Properties)78 OutputVariable (org.evosuite.statistics.OutputVariable)50 GenericSUTString (com.examples.with.different.packagename.generic.GenericSUTString)49 TestChromosome (org.evosuite.testcase.TestChromosome)47 BranchCoverageSuiteFitness (org.evosuite.coverage.branch.BranchCoverageSuiteFitness)44 TestCase (org.evosuite.testcase.TestCase)43 TestFitnessFunction (org.evosuite.testcase.TestFitnessFunction)30 DefaultTestCase (org.evosuite.testcase.DefaultTestCase)22 Ignore (org.junit.Ignore)19 ArrayList (java.util.ArrayList)17 DefaultLocalSearchObjective (org.evosuite.ga.localsearch.DefaultLocalSearchObjective)17 TestSuiteFitnessFunction (org.evosuite.testsuite.TestSuiteFitnessFunction)14 CheapPurityAnalyzer (org.evosuite.assertion.CheapPurityAnalyzer)13 LineCoverageSuiteFitness (org.evosuite.coverage.line.LineCoverageSuiteFitness)13 InstrumentingClassLoader (org.evosuite.instrumentation.InstrumentingClassLoader)13 ExecutionResult (org.evosuite.testcase.execution.ExecutionResult)10 Method (java.lang.reflect.Method)9