Search in sources :

Example 16 with SearchStatistics

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

the class CoverageAnalysisOfClassSystemTest method testOneClassOneCriterion.

@Test
public void testOneClassOneCriterion() {
    EvoSuite evosuite = new EvoSuite();
    String targetClass = Calculator.class.getCanonicalName();
    String testClass = CalculatorTest.class.getCanonicalName();
    Properties.TARGET_CLASS = targetClass;
    Properties.CRITERION = new Properties.Criterion[] { Properties.Criterion.BRANCH };
    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(0.80, (Double) outputVariables.get("BranchCoverage").getValue(), 0.0);
    assertEquals(0.80, (Double) outputVariables.get("Coverage").getValue(), 0.0);
    assertEquals(4, (Integer) outputVariables.get("Tests_Executed").getValue(), 0);
    assertEquals(4, (Integer) outputVariables.get("Covered_Goals").getValue(), 0);
    assertEquals(5, (Integer) outputVariables.get("Total_Goals").getValue(), 0);
    assertEquals("10111", outputVariables.get("BranchCoverageBitString").getValue());
}
Also used : SearchStatistics(org.evosuite.statistics.SearchStatistics) EvoSuite(org.evosuite.EvoSuite) Properties(org.evosuite.Properties) OutputVariable(org.evosuite.statistics.OutputVariable) Test(org.junit.Test) CalculatorTest(com.examples.with.different.packagename.CalculatorTest)

Example 17 with SearchStatistics

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

the class CoverageAnalysisOfProjectSystemTest method testMoreThanOneClassOneCriterion.

@Test
public void testMoreThanOneClassOneCriterion() throws IOException {
    createFakeProject();
    EvoSuite evosuite = new EvoSuite();
    Properties.CRITERION = new Properties.Criterion[] { Properties.Criterion.LINE };
    Properties.STATISTICS_BACKEND = StatisticsBackend.CSV;
    String[] command = new String[] { "-target", this.classes_directory.getAbsolutePath(), "-Djunit=" + this.tests_directory.getAbsolutePath(), "-projectCP", this.classes_directory.getAbsolutePath() + File.pathSeparator + this.tests_directory.getAbsolutePath(), "-measureCoverage" };
    SearchStatistics statistics = (SearchStatistics) evosuite.parseCommandLine(command);
    Assert.assertNotNull(statistics);
    String statistics_file = System.getProperty("user.dir") + File.separator + Properties.REPORT_DIR + File.separator + "statistics.csv";
    CSVReader reader = new CSVReader(new FileReader(statistics_file));
    List<String[]> rows = reader.readAll();
    // header + 7 classes
    assertEquals(8, rows.size());
    reader.close();
    // assert TargetClasses
    List<String> classes = CsvJUnitData.getValues(rows, "TARGET_CLASS");
    assertTrue(classes.contains(Calculator.class.getCanonicalName()));
    assertTrue(classes.contains(MethodWithSeveralInputArguments.class.getCanonicalName()));
    assertTrue(classes.contains(WordUtils.class.getCanonicalName()));
    assertTrue(classes.contains(FinalClass.class.getCanonicalName()));
    assertTrue(classes.contains(StringUtils.class.getCanonicalName()));
    assertTrue(classes.contains(ClassNumberUtils.class.getCanonicalName()));
    assertTrue(classes.contains(ClassWithPrivateInterfaces.class.getCanonicalName()));
    // assert Coverage
    List<String> coverages = CsvJUnitData.getValues(rows, "Coverage");
    assertTrue(coverages.size() == 7);
    Collections.sort(coverages);
    assertEquals(0.80, Double.valueOf(coverages.get(0)), 0.01);
    assertEquals(0.80, Double.valueOf(coverages.get(1)), 0.00);
    assertEquals(0.90, Double.valueOf(coverages.get(2)), 0.00);
    assertEquals(0.93, Double.valueOf(coverages.get(3)), 0.01);
    assertEquals(0.95, Double.valueOf(coverages.get(4)), 0.00);
    assertEquals(1.00, Double.valueOf(coverages.get(5)), 0.00);
    assertEquals(1.00, Double.valueOf(coverages.get(6)), 0.00);
}
Also used : SearchStatistics(org.evosuite.statistics.SearchStatistics) CSVReader(com.opencsv.CSVReader) EvoSuite(org.evosuite.EvoSuite) FileReader(java.io.FileReader) Properties(org.evosuite.Properties) ClassWithPrivateInterfacesTest(com.examples.with.different.packagename.ClassWithPrivateInterfacesTest) FinalClassTest(com.examples.with.different.packagename.FinalClassTest) StringUtilsEqualsIndexOfTest(com.examples.with.different.packagename.StringUtilsEqualsIndexOfTest) WordUtilsTest(com.examples.with.different.packagename.WordUtilsTest) ClassNumberUtilsTest(com.examples.with.different.packagename.ClassNumberUtilsTest) Test(org.junit.Test) CalculatorTest(com.examples.with.different.packagename.CalculatorTest)

Example 18 with SearchStatistics

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

the class CoverageAnalysisSystemTest method testBranchCoverage.

@Test
public void testBranchCoverage() {
    SearchStatistics statistics = this.aux(new Properties.Criterion[] { Properties.Criterion.BRANCH });
    Map<String, OutputVariable<?>> variables = statistics.getOutputVariables();
    assertEquals(9, (Integer) variables.get("Total_Goals").getValue(), 0.0);
    assertEquals(9, (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 19 with SearchStatistics

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

the class CoverageAnalysisSystemTest method testLineCoverage.

@Test
public void testLineCoverage() {
    SearchStatistics statistics = this.aux(new Properties.Criterion[] { Properties.Criterion.LINE });
    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 20 with SearchStatistics

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

the class CoverageAnalysisSystemTest method testCBranchCoverage.

@Test
public void testCBranchCoverage() {
    SearchStatistics statistics = this.aux(new Properties.Criterion[] { Properties.Criterion.CBRANCH });
    Map<String, OutputVariable<?>> variables = statistics.getOutputVariables();
    assertEquals(9, (Integer) variables.get("Total_Goals").getValue(), 0.0);
    assertEquals(9, (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)

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