Search in sources :

Example 11 with SearchStatistics

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

the class CoverageAnalysisSystemTest method testAmbiguityCoverage.

@Test
public void testAmbiguityCoverage() {
    SearchStatistics statistics = this.aux(new Properties.Criterion[] { Properties.Criterion.AMBIGUITY });
    Map<String, OutputVariable<?>> variables = statistics.getOutputVariables();
    assertEquals(11, (Integer) variables.get("Total_Goals").getValue(), 0.0);
    assertEquals(11, (Integer) variables.get("Covered_Goals").getValue(), 0.0);
}
Also used : SearchStatistics(org.evosuite.statistics.SearchStatistics) Properties(org.evosuite.Properties) OutputVariable(org.evosuite.statistics.OutputVariable) Test(org.junit.Test)

Example 12 with SearchStatistics

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

the class CoverageAnalysisSystemTest method testOnlyLineCoverage.

@Test
public void testOnlyLineCoverage() {
    SearchStatistics statistics = this.aux(new Properties.Criterion[] { Properties.Criterion.ONLYLINE });
    Map<String, OutputVariable<?>> variables = statistics.getOutputVariables();
    assertEquals(11, (Integer) variables.get("Total_Goals").getValue(), 0.0);
    assertEquals(11, (Integer) variables.get("Covered_Goals").getValue(), 0.0);
}
Also used : SearchStatistics(org.evosuite.statistics.SearchStatistics) Properties(org.evosuite.Properties) OutputVariable(org.evosuite.statistics.OutputVariable) Test(org.junit.Test)

Example 13 with SearchStatistics

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

the class CoverageAnalysisSystemTest method testOnlyBranchCoverage.

@Test
public void testOnlyBranchCoverage() {
    SearchStatistics statistics = this.aux(new Properties.Criterion[] { Properties.Criterion.ONLYBRANCH });
    Map<String, OutputVariable<?>> variables = statistics.getOutputVariables();
    assertEquals(8, (Integer) variables.get("Total_Goals").getValue(), 0.0);
    assertEquals(8, (Integer) variables.get("Covered_Goals").getValue(), 0.0);
}
Also used : SearchStatistics(org.evosuite.statistics.SearchStatistics) Properties(org.evosuite.Properties) OutputVariable(org.evosuite.statistics.OutputVariable) Test(org.junit.Test)

Example 14 with SearchStatistics

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

the class CoverageAnalysisFinalClassSystemTest method test.

@Test
public void test() throws IOException {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = FinalClass.class.getCanonicalName();
    String testClass = FinalClassTest.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.CRITERION = new Properties.Criterion[] { Properties.Criterion.LINE };
    Properties.OUTPUT_VARIABLES = RuntimeVariable.Total_Goals + "," + RuntimeVariable.LineCoverage;
    Properties.STATISTICS_BACKEND = StatisticsBackend.CSV;
    Properties.COVERAGE_MATRIX = true;
    String[] command = new String[] { "-class", targetClass, "-Djunit=" + testClass, "-measureCoverage" };
    SearchStatistics statistics = (SearchStatistics) evosuite.parseCommandLine(command);
    Assert.assertNotNull(statistics);
    Map<String, OutputVariable<?>> outputVariables = statistics.getOutputVariables();
    assertEquals(2, (Integer) outputVariables.get(RuntimeVariable.Total_Goals.name()).getValue(), 0.0);
    assertEquals(2, (Integer) outputVariables.get(RuntimeVariable.Covered_Goals.name()).getValue(), 0.0);
    assertEquals(1, (Double) outputVariables.get(RuntimeVariable.LineCoverage.name()).getValue(), 0.0);
    assertEquals(1, (Integer) outputVariables.get(RuntimeVariable.Tests_Executed.name()).getValue(), 0.0);
    // check coverage matrix
    String coveragematrix_file = System.getProperty("user.dir") + File.separator + Properties.REPORT_DIR + File.separator + "data" + File.separator + Properties.TARGET_CLASS + File.separator + Properties.Criterion.LINE.name() + File.separator + Properties.COVERAGE_MATRIX_FILENAME;
    System.out.println("CoverageMatrix file " + coveragematrix_file);
    List<String> lines = Files.readAllLines(Paths.get(coveragematrix_file));
    // coverage of one test case
    assertEquals(1, lines.size());
    // the test case pass ("+")
    assertTrue(lines.get(0).contains("+"));
}
Also used : SearchStatistics(org.evosuite.statistics.SearchStatistics) EvoSuite(org.evosuite.EvoSuite) Properties(org.evosuite.Properties) OutputVariable(org.evosuite.statistics.OutputVariable) FinalClassTest(com.examples.with.different.packagename.FinalClassTest) Test(org.junit.Test)

Example 15 with SearchStatistics

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

the class CarverSystemTest method testJodaTestScaledDurationField.

@Test
public void testJodaTestScaledDurationField() {
    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 = TestScaledDurationField.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) Test(org.junit.Test)

Aggregations

SearchStatistics (org.evosuite.statistics.SearchStatistics)23 Test (org.junit.Test)22 Properties (org.evosuite.Properties)21 OutputVariable (org.evosuite.statistics.OutputVariable)19 EvoSuite (org.evosuite.EvoSuite)16 CalculatorTest (com.examples.with.different.packagename.CalculatorTest)5 ClassNumberUtilsTest (com.examples.with.different.packagename.ClassNumberUtilsTest)3 ClassWithPrivateInterfacesTest (com.examples.with.different.packagename.ClassWithPrivateInterfacesTest)3 FinalClassTest (com.examples.with.different.packagename.FinalClassTest)3 StringUtilsEqualsIndexOfTest (com.examples.with.different.packagename.StringUtilsEqualsIndexOfTest)3 WordUtilsTest (com.examples.with.different.packagename.WordUtilsTest)3 CSVReader (com.opencsv.CSVReader)3 FileReader (java.io.FileReader)3 Ignore (org.junit.Ignore)2 ClassHierarchyIncludingInterfacesTest (com.examples.with.different.packagename.ClassHierarchyIncludingInterfacesTest)1 ClassPublicInterfaceTest (com.examples.with.different.packagename.ClassPublicInterfaceTest)1