@Test public void test() throws IOException { EvoSuite evosuite = new EvoSuite(); String targetClass = StringUtils.class.getCanonicalName(); String testClass = StringUtilsEqualsIndexOfTest.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( 9, (Integer) outputVariables.get(RuntimeVariable.Total_Goals.name()).getValue(), 0.0); assertEquals( 8, (Integer) outputVariables.get(RuntimeVariable.Covered_Goals.name()).getValue(), 0.0); assertEquals( 8.0 / 9.0, (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 + "." + Properties.Criterion.LINE.name() + ".matrix"; 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()); // all components have been covered ("1"), and the test case pass ("+") assertTrue(lines.get(0).contains("+")); }
@Test public void testGetAllInterfaces() throws IOException { EvoSuite evosuite = new EvoSuite(); String targetClass = ClassWithPrivateInterfaces.class.getCanonicalName(); String testClass = ClassWithPrivateInterfacesTest.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"}; Object statistics = evosuite.parseCommandLine(command); Assert.assertNotNull(statistics); // Assert coverage String statistics_file = System.getProperty("user.dir") + File.separator + Properties.REPORT_DIR + File.separator + "statistics.csv"; System.out.println("statistics_file: " + statistics_file); CSVReader reader = new CSVReader(new FileReader(statistics_file)); List<String[]> rows = reader.readAll(); assertTrue(rows.size() == 2); reader.close(); assertEquals("14", CsvJUnitData.getValue(rows, RuntimeVariable.Total_Goals.name())); assertEquals( 0.93, Double.valueOf(CsvJUnitData.getValue(rows, RuntimeVariable.LineCoverage.name())), 0.01); // Assert that all test cases have passed String matrix_file = System.getProperty("user.dir") + File.separator + Properties.REPORT_DIR + File.separator + "data" + File.separator + targetClass + File.separator + Properties.Criterion.LINE.name() + File.separator + Properties.COVERAGE_MATRIX_FILENAME; System.out.println("matrix_file: " + matrix_file); List<String> lines = Files.readAllLines(FileSystems.getDefault().getPath(matrix_file)); assertTrue(lines.size() == 1); assertEquals( 13 + 1 + 1, lines .get(0) .replace(" ", "") .length()); // number of goals + test result ('+' pass, '-' fail) assertTrue(lines.get(0).replace(" ", "").endsWith("+")); }