Search in sources :

Example 16 with EvoSuite

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

the class OutputCoverageFitnessFunctionSystemTest method testOutputCoverageObjectType.

public void testOutputCoverageObjectType() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = MethodReturnsObject.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();
    int goals = 0;
    for (TestFitnessFactory ff : TestGenerationStrategy.getFitnessFactories()) goals += ff.getCoverageGoals().size();
    Assert.assertEquals("Unexpected number of goals", 14, goals);
    // sub-optimal due to hashcode observer
    Assert.assertEquals("Unexpected coverage: ", 0.888d, best.getCoverage(), 0.001);
}
Also used : EvoSuite(org.evosuite.EvoSuite) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) MethodReturnsObject(com.examples.with.different.packagename.coverage.MethodReturnsObject) TestFitnessFactory(org.evosuite.coverage.TestFitnessFactory)

Example 17 with EvoSuite

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

the class BaseDeterminismSystemTest method run.

private static String run(Class<?> target, Runnable initializer) {
    SystemTestBase scaffolding = new SystemTestBase();
    ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
    PrintStream outStream = new PrintStream(byteStream);
    PrintStream latestOut = System.out;
    System.setOut(outStream);
    // @Before
    scaffolding.setDefaultPropertiesForTestCases();
    Properties.CRITERION = new Properties.Criterion[] { Properties.Criterion.LINE, Properties.Criterion.BRANCH, Properties.Criterion.EXCEPTION, Properties.Criterion.WEAKMUTATION, Properties.Criterion.OUTPUT, Properties.Criterion.METHOD, Properties.Criterion.METHODNOEXCEPTION, Properties.Criterion.CBRANCH };
    if (initializer != null) {
        initializer.run();
    }
    boolean defaultPrint = Properties.PRINT_TO_SYSTEM;
    Properties.PRINT_TO_SYSTEM = true;
    try {
        EvoSuite evosuite = new EvoSuite();
        String targetClass = target.getCanonicalName();
        Properties.TARGET_CLASS = targetClass;
        String[] command = new String[] { "-generateSuite", "-class", targetClass };
        evosuite.parseCommandLine(command);
    } finally {
        // @After
        scaffolding.resetStaticVariables();
        System.setOut(latestOut);
        Properties.PRINT_TO_SYSTEM = defaultPrint;
    }
    return filter(byteStream.toString());
}
Also used : PrintStream(java.io.PrintStream) EvoSuite(org.evosuite.EvoSuite) SystemTestBase(org.evosuite.SystemTestBase) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Properties(org.evosuite.Properties)

Example 18 with EvoSuite

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

the class CurrentTimeSystemTest method testCurrentTimeViaDateParameter.

@Test
public void testCurrentTimeViaDateParameter() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = CurrentTimeViaDateParameter.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.REPLACE_CALLS = true;
    // Properties.USE_DEPRECATED = false; // TODO why does the test pass only if USE_DEPRECATED is false???
    String[] command = new String[] { "-generateSuite", "-class", targetClass };
    Object result = evosuite.parseCommandLine(command);
    GeneticAlgorithm<?> ga = getGAFromResult(result);
    TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
    java.lang.System.out.println("Test Suite: " + best.toString());
    // 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)

Example 19 with EvoSuite

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

the class CurrentTimeSystemTest method testCurrentTimeViaCalendar1.

@Test
public void testCurrentTimeViaCalendar1() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = CurrentTimeViaCalendar1.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.REPLACE_CALLS = true;
    String[] command = new String[] { "-generateSuite", "-class", targetClass };
    Object result = evosuite.parseCommandLine(command);
    GeneticAlgorithm<?> ga = getGAFromResult(result);
    TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
    // 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)

Example 20 with EvoSuite

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

the class CurrentTimeSystemTest method testCurrentTime1.

@Test
public void testCurrentTime1() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = CurrentTime.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.REPLACE_CALLS = true;
    String[] command = new String[] { "-generateSuite", "-class", targetClass };
    Object result = evosuite.parseCommandLine(command);
    GeneticAlgorithm<?> ga = getGAFromResult(result);
    TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
    // 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

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