Search in sources :

Example 46 with TestSuiteChromosome

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

the class ServletSystemTest method testSimpleCase_noJEE.

@Test
public void testSimpleCase_noJEE() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = SimpleHttpServlet.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.CRITERION = new Properties.Criterion[] { Properties.Criterion.LINE };
    Properties.JEE = false;
    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);
    Assert.assertTrue(best.getCoverage() < 1);
}
Also used : EvoSuite(org.evosuite.EvoSuite) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) Properties(org.evosuite.Properties) Test(org.junit.Test)

Example 47 with TestSuiteChromosome

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

the class CookieSystemTest method testZ3DSE.

@Test
public void testZ3DSE() {
    if (System.getenv("z3_path") == null) {
        System.out.println("z3_path should be configured for running this test case");
        return;
    }
    Properties.Z3_PATH = System.getenv("z3_path");
    Properties.DSE_SOLVER = SolverType.Z3_SOLVER;
    Properties.STOPPING_CONDITION = StoppingCondition.MAXTIME;
    Properties.SEARCH_BUDGET = 120;
    // should it be trivial for DSE ?
    EvoSuite evosuite = new EvoSuite();
    String targetClass = Cookie.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.CRITERION = new Criterion[] { Criterion.LINE, Criterion.BRANCH, Criterion.EXCEPTION, Criterion.WEAKMUTATION, Criterion.OUTPUT, Criterion.METHOD, Criterion.METHODNOEXCEPTION, Criterion.CBRANCH };
    Properties.MINIMIZE = false;
    Properties.ASSERTIONS = false;
    // force using only DSE, no LS
    Properties.DSE_PROBABILITY = 1.0;
    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 48 with TestSuiteChromosome

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

the class DseWithUrlSystemTest method testDSE.

@Test
public void testDSE() {
    Properties.DSE_SOLVER = SolverType.EVOSUITE_SOLVER;
    Properties.STOPPING_CONDITION = StoppingCondition.MAXTIME;
    Properties.SEARCH_BUDGET = 120;
    // should it be trivial for DSE ?
    EvoSuite evosuite = new EvoSuite();
    String targetClass = DseWithURL.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.CRITERION = new Criterion[] { Criterion.BRANCH, Criterion.EXCEPTION };
    Properties.MINIMIZE = true;
    Properties.ASSERTIONS = true;
    // force using only DSE, no LS
    Properties.DSE_PROBABILITY = 1.0;
    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 49 with TestSuiteChromosome

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

the class ExampleHardForGASystemTest method testZ3.

@Test
public void testZ3() {
    Assume.assumeTrue(System.getenv("z3_path") != null);
    Properties.Z3_PATH = System.getenv("z3_path");
    Properties.DSE_SOLVER = SolverType.Z3_SOLVER;
    Properties.LOCAL_SEARCH_PROBABILITY = 1.0;
    Properties.LOCAL_SEARCH_RATE = 8;
    Properties.LOCAL_SEARCH_BUDGET_TYPE = Properties.LocalSearchBudgetType.TESTS;
    Properties.LOCAL_SEARCH_BUDGET = 10;
    // force using only DSE, no LS
    Properties.DSE_PROBABILITY = 1.0;
    Properties.CONCOLIC_TIMEOUT = 1000;
    EvoSuite evosuite = new EvoSuite();
    String targetClass = ExampleHardForGA.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    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);
    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 50 with TestSuiteChromosome

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

the class ExampleHardForGASystemTest method testBase.

/**
 * It is expected that the regular GA will not be able to cover all the
 * branches in the given budget, but using a constraint solver will do it
 */
@Test
public void testBase() {
    // disable LS
    Properties.LOCAL_SEARCH_RATE = -1;
    EvoSuite evosuite = new EvoSuite();
    String targetClass = ExampleHardForGA.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    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);
    /**
     * We expect the coverage will not be 100% branch, since there is at
     * least one branch that is particularly hard for GA
     */
    Assert.assertTrue(best.getCoverage() < 1d);
}
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