Search in sources :

Example 41 with EvoSuite

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

Example 42 with EvoSuite

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

the class HardConstraintsNoDSESystemTest method test.

@Test
public void test() {
    Properties.RESET_STATIC_FIELD_GETS = true;
    Properties.STOPPING_CONDITION = StoppingCondition.MAXTIME;
    Properties.SEARCH_BUDGET = 60;
    EvoSuite evosuite = new EvoSuite();
    String targetClass = HardConstraints.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.CRITERION = new Criterion[] { Criterion.BRANCH, Criterion.EXCEPTION };
    Properties.MINIMIZE = true;
    Properties.ASSERTIONS = true;
    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 43 with EvoSuite

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

the class Issta14SystemTest method testLocalSearch.

@Test
public void testLocalSearch() {
    // it should be trivial for LS
    EvoSuite evosuite = new EvoSuite();
    String targetClass = IsstaFoo.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    // force using only LS, no DSE
    Properties.DSE_PROBABILITY = 0.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);
    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 44 with EvoSuite

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

the class LO_OtherSystemTest method testBase.

@Test
public void testBase() {
    // disable LS/DSE
    Properties.LOCAL_SEARCH_RATE = -1;
    String targetClass = LO_Other.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.CRITERION = new Criterion[] { Criterion.BRANCH };
    String[] command = new String[] { "-generateSuite", "-class", targetClass };
    EvoSuite evosuite = new EvoSuite();
    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 45 with EvoSuite

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

the class LO_OtherSystemTest method testDSE.

@Test
public void testDSE() {
    Properties.LOCAL_SEARCH_PROBABILITY = 1.0;
    Properties.LOCAL_SEARCH_RATE = 8;
    Properties.LOCAL_SEARCH_BUDGET_TYPE = Properties.LocalSearchBudgetType.TESTS;
    Properties.LOCAL_SEARCH_BUDGET = 100;
    // force DSE, not LS
    Properties.DSE_PROBABILITY = 1.0;
    Properties.DSE_SOLVER = Properties.SolverType.EVOSUITE_SOLVER;
    // no timeout
    Properties.CONCOLIC_TIMEOUT = Integer.MAX_VALUE;
    String targetClass = LO_Other.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.CRITERION = new Criterion[] { Criterion.BRANCH };
    String[] command = new String[] { "-generateSuite", "-class", targetClass };
    EvoSuite evosuite = new EvoSuite();
    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