Search in sources :

Example 46 with EvoSuite

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

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

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

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

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

the class LambdaInStaticConstructorSystemTest method testNoCrashInCLINIT.

@Test
public void testNoCrashInCLINIT() throws Throwable {
    String targetClass = LambdaInStaticConstructor.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.TIMEOUT = 50000000;
    Properties.RESET_STATIC_FINAL_FIELDS = true;
    EvoSuite evosuite = new EvoSuite();
    String[] command = new String[] { "-generateSuite", "-class", targetClass };
    Object result = evosuite.parseCommandLine(command);
    GeneticAlgorithm<?> ga = getGAFromResult(result);
    TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
    System.out.println(best.toString());
}
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