Search in sources :

Example 66 with EvoSuite

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

the class TimelineForCombinedFitness1SystemTest method testTimelineForCombinedFitness.

@Test
public void testTimelineForCombinedFitness() {
    EvoSuite evosuite = new EvoSuite();
    Properties.ASSERTIONS = false;
    String targetClass = Compositional.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.CRITERION = new Properties.Criterion[4];
    Properties.CRITERION[0] = Properties.Criterion.ONLYBRANCH;
    Properties.CRITERION[1] = Properties.Criterion.METHODNOEXCEPTION;
    Properties.CRITERION[2] = Properties.Criterion.METHOD;
    Properties.CRITERION[3] = Properties.Criterion.OUTPUT;
    StringBuilder s = new StringBuilder();
    s.append(RuntimeVariable.CoverageTimeline);
    s.append(",");
    s.append(RuntimeVariable.OnlyBranchCoverageTimeline);
    s.append(",");
    s.append(RuntimeVariable.MethodCoverageTimeline);
    s.append(",");
    s.append(RuntimeVariable.MethodNoExceptionCoverageTimeline);
    s.append(",");
    s.append(RuntimeVariable.OutputCoverageTimeline);
    Properties.OUTPUT_VARIABLES = s.toString();
    String[] command = new String[] { "-generateSuite", "-class", targetClass };
    evosuite.parseCommandLine(command);
    Map<String, OutputVariable<?>> map = DebugStatisticsBackend.getLatestWritten();
    Assert.assertNotNull(map);
    String strVar1 = RuntimeVariable.MethodCoverageTimeline.toString();
    OutputVariable method = getLastTimelineVariable(map, strVar1);
    Assert.assertNotNull(method);
    Assert.assertEquals("Incorrect last timeline value for " + strVar1, 1.0, method.getValue());
    String strVar2 = RuntimeVariable.MethodNoExceptionCoverageTimeline.toString();
    OutputVariable methodNE = getLastTimelineVariable(map, strVar2);
    Assert.assertNotNull(methodNE);
    Assert.assertEquals("Incorrect last timeline value for " + strVar2, 1.0, methodNE.getValue());
    String strVar3 = RuntimeVariable.OutputCoverageTimeline.toString();
    OutputVariable output = getLastTimelineVariable(map, strVar3);
    Assert.assertNotNull(output);
    Assert.assertEquals("Incorrect last timeline value for " + strVar3, 1.0, output.getValue());
}
Also used : EvoSuite(org.evosuite.EvoSuite) Properties(org.evosuite.Properties) Test(org.junit.Test)

Example 67 with EvoSuite

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

the class CarverSystemTest method testPublicStaticField.

@Test
public void testPublicStaticField() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = Days.class.getCanonicalName();
    // Test suite with private static field.
    String testClass = TestDaysWithPublicField.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.JUNIT_TESTS = true;
    Properties.CRITERION = new Properties.Criterion[] { Properties.Criterion.BRANCH, Properties.Criterion.METHOD };
    String[] command = new String[] { "-class", targetClass, "-Djunit=" + testClass, "-Dselected_junit=" + testClass, "-measureCoverage" };
    SearchStatistics result = (SearchStatistics) evosuite.parseCommandLine(command);
    Assert.assertNotNull(result);
    OutputVariable coverage = (OutputVariable) result.getOutputVariables().get("Coverage");
    Assert.assertEquals("Non-optimal coverage", 1d, (double) coverage.getValue(), 0.01);
}
Also used : SearchStatistics(org.evosuite.statistics.SearchStatistics) EvoSuite(org.evosuite.EvoSuite) Properties(org.evosuite.Properties) OutputVariable(org.evosuite.statistics.OutputVariable) Test(org.junit.Test)

Example 68 with EvoSuite

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

the class CarverSystemTest method testPrivateStaticField.

// There doesn't seem to be an easy solution to this so let's ignore it for now
@Ignore
@Test
public void testPrivateStaticField() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = Days.class.getCanonicalName();
    // Test suite with private static field.
    String testClass = TestDays.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.JUNIT_TESTS = true;
    Properties.CRITERION = new Properties.Criterion[] { Properties.Criterion.BRANCH, Properties.Criterion.METHOD };
    String[] command = new String[] { "-class", targetClass, "-Djunit=" + testClass, "-Dselected_junit=" + testClass, "-measureCoverage" };
    SearchStatistics result = (SearchStatistics) evosuite.parseCommandLine(command);
    Assert.assertNotNull(result);
    OutputVariable coverage = (OutputVariable) result.getOutputVariables().get("Coverage");
    Assert.assertEquals("Non-optimal coverage", 1d, (double) coverage.getValue(), 0.01);
}
Also used : SearchStatistics(org.evosuite.statistics.SearchStatistics) EvoSuite(org.evosuite.EvoSuite) Properties(org.evosuite.Properties) OutputVariable(org.evosuite.statistics.OutputVariable) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 69 with EvoSuite

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

the class CarverSystemTest method testJodaTestScaledDurationFieldWithException.

// An exception is thrown in the constructor. There is nothing that can be carved...
@Ignore
@Test
public void testJodaTestScaledDurationFieldWithException() {
    EvoSuite evosuite = new EvoSuite();
    // TestScaledDurationField.test_constructor causes NoSuchMethodException,
    // possibly related to a super() call in ScaledDurationField's constructor
    String targetClass = ScaledDurationField.class.getCanonicalName();
    String testClass = TestScaledDurationFieldWithException.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.JUNIT_TESTS = true;
    Properties.PRINT_GOALS = true;
    Properties.CRITERION = new Properties.Criterion[] { Properties.Criterion.BRANCH, Properties.Criterion.METHOD };
    Properties.GLOBAL_TIMEOUT = 600;
    String[] command = new String[] { "-class", targetClass, "-Djunit=" + testClass, "-Dselected_junit=" + testClass, "-measureCoverage" };
    SearchStatistics result = (SearchStatistics) evosuite.parseCommandLine(command);
    Assert.assertNotNull(result);
    OutputVariable coverage = (OutputVariable) result.getOutputVariables().get("MethodCoverage");
    Assert.assertEquals("Non-optimal method coverage value", 1d, (double) coverage.getValue(), 0.01);
}
Also used : SearchStatistics(org.evosuite.statistics.SearchStatistics) EvoSuite(org.evosuite.EvoSuite) Properties(org.evosuite.Properties) OutputVariable(org.evosuite.statistics.OutputVariable) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 70 with EvoSuite

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

the class NoClassInitSystemTest method test.

@Test
public void test() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = NoClassInit.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);
    double best_fitness = best.getFitness();
    Assert.assertTrue("Optimal coverage was not achieved ", best_fitness == 0.0);
}
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