Search in sources :

Example 56 with TestSuiteChromosome

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

the class RegexSystemTest method testDSE.

@Test
public void testDSE() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = Regex.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.PRINT_TO_SYSTEM = true;
    // force using only DSE, no LS
    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 57 with TestSuiteChromosome

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

the class BreederGASystemTest method testLambdaGAIntegration.

@Test
public void testLambdaGAIntegration() {
    Properties.ALGORITHM = Properties.Algorithm.BREEDER_GA;
    Properties.TRUNCATION_RATE = 0.1;
    EvoSuite evoSuite = new EvoSuite();
    String targetClass = BMICalculator.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    String[] command = new String[] { "-generateSuite", "-class", targetClass };
    Object result = evoSuite.parseCommandLine(command);
    GeneticAlgorithm<?> ga = getGAFromResult(result);
    Assert.assertEquals(BreederGA.class, ga.getClass());
    TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
    System.out.println("EvolvedTestSuite:\n" + best);
    Assert.assertEquals(0.0, best.getFitness(), 0.0);
    Assert.assertEquals(1d, best.getCoverage(), 0.001);
}
Also used : EvoSuite(org.evosuite.EvoSuite) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) Test(org.junit.Test)

Example 58 with TestSuiteChromosome

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

the class MIOSystemTest method test.

private void test(double exploitation_starts_at_percent) {
    Properties.ALGORITHM = Properties.Algorithm.MIO;
    Properties.ARCHIVE_TYPE = Properties.ArchiveType.MIO;
    Properties.NUMBER_OF_TESTS_PER_TARGET = 3;
    Properties.EXPLOITATION_STARTS_AT_PERCENT = exploitation_starts_at_percent;
    String targetClass = BMICalculator.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    String[] command = new String[] { "-generateSuite", "-class", targetClass };
    EvoSuite evoSuite = new EvoSuite();
    GeneticAlgorithm<?> ga = getGAFromResult(evoSuite.parseCommandLine(command));
    Assert.assertEquals(MIO.class, ga.getClass());
    TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
    System.out.println("EvolvedTestSuite:\n" + best);
    Assert.assertEquals(0.0, best.getFitness(), 0.0);
    Assert.assertEquals(1d, best.getCoverage(), 0.001);
}
Also used : EvoSuite(org.evosuite.EvoSuite) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome)

Example 59 with TestSuiteChromosome

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

the class OnePlusOneEASystemTest method systemtTestLambdaEA.

@Test
public void systemtTestLambdaEA() {
    Properties.ALGORITHM = Algorithm.ONE_PLUS_ONE_EA;
    EvoSuite evoSuite = new EvoSuite();
    String targetClass = BMICalculator.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(0.0, best.getFitness(), 0.0);
    Assert.assertEquals(1d, best.getCoverage(), 0.001);
}
Also used : EvoSuite(org.evosuite.EvoSuite) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) Test(org.junit.Test)

Example 60 with TestSuiteChromosome

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

the class StandardChemicalReactionSystemTest method testIntegration.

@Test
public void testIntegration() {
    GeneticAlgorithm<?> ga = test(0.2, 500, 10);
    TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
    System.out.println("EvolvedTestSuite:\n" + best);
    // the integration test must covers all goals as it uses all functionalities
    Assert.assertEquals(0.0, best.getFitness(), 0.0);
    Assert.assertEquals(1d, best.getCoverage(), 0.001);
}
Also used : 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