use of org.evosuite.statistics.SearchStatistics 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);
}
use of org.evosuite.statistics.SearchStatistics 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);
}
use of org.evosuite.statistics.SearchStatistics in project evosuite by EvoSuite.
the class CoverageAnalysisOfClassSystemTest method testMeasureCoverageOfCarvedTests.
@Test
public void testMeasureCoverageOfCarvedTests() {
EvoSuite evosuite = new EvoSuite();
String targetClass = MethodWithSeveralInputArguments.class.getCanonicalName();
String testClass = TestMethodWithSeveralInputArguments.class.getCanonicalName();
Properties.TARGET_CLASS = targetClass;
Properties.CRITERION = new Properties.Criterion[] { Properties.Criterion.INPUT, Properties.Criterion.METHOD, Properties.Criterion.OUTPUT };
String[] command = new String[] { "-class", targetClass, "-Djunit=" + testClass, "-Dselected_junit=" + testClass, "-measureCoverage" };
SearchStatistics result = (SearchStatistics) evosuite.parseCommandLine(command);
Assert.assertNotNull(result);
OutputVariable<?> methodCoverage = (OutputVariable<?>) result.getOutputVariables().get(RuntimeVariable.MethodCoverage.name());
OutputVariable<?> inputCoverage = (OutputVariable<?>) result.getOutputVariables().get(RuntimeVariable.InputCoverage.name());
OutputVariable<?> outputCoverage = (OutputVariable<?>) result.getOutputVariables().get(RuntimeVariable.OutputCoverage.name());
Assert.assertEquals("Unexpected method coverage value", 1d, (Double) methodCoverage.getValue(), 0.01);
Assert.assertEquals("Unexpected input coverage value", 0.67d, (Double) inputCoverage.getValue(), 0.01);
Assert.assertEquals("Unexpected output coverage value", 0.33d, (Double) outputCoverage.getValue(), 0.01);
}
use of org.evosuite.statistics.SearchStatistics in project evosuite by EvoSuite.
the class CoverageAnalysisOfClassSystemTest method testOneClassMoreThanOneCriterion.
@Test
public void testOneClassMoreThanOneCriterion() throws IOException {
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, Properties.Criterion.LINE };
Properties.OUTPUT_VARIABLES = "TARGET_CLASS,criterion," + RuntimeVariable.Coverage.name() + "," + RuntimeVariable.Covered_Goals + "," + RuntimeVariable.Total_Goals + "," + RuntimeVariable.BranchCoverage + "," + RuntimeVariable.BranchCoverageBitString + "," + RuntimeVariable.LineCoverage + "," + RuntimeVariable.LineCoverageBitString;
Properties.STATISTICS_BACKEND = StatisticsBackend.CSV;
String[] command = new String[] { "-class", targetClass, "-Djunit=" + testClass, "-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";
System.out.println(statistics_file);
CSVReader reader = new CSVReader(new FileReader(statistics_file));
List<String[]> rows = reader.readAll();
assertTrue(rows.size() == 2);
reader.close();
assertTrue(CsvJUnitData.getValue(rows, "TARGET_CLASS").equals(Calculator.class.getCanonicalName()));
assertTrue(CsvJUnitData.getValue(rows, "criterion").equals(Properties.Criterion.BRANCH.toString() + ";" + Properties.Criterion.LINE.toString()));
assertEquals(0.8, Double.valueOf(CsvJUnitData.getValue(rows, RuntimeVariable.Coverage.name())), 0.01);
assertEquals(8, (int) Integer.valueOf(CsvJUnitData.getValue(rows, RuntimeVariable.Covered_Goals.name())));
assertEquals(10, (int) Integer.valueOf(CsvJUnitData.getValue(rows, RuntimeVariable.Total_Goals.name())));
assertEquals(0.8, Double.valueOf(CsvJUnitData.getValue(rows, RuntimeVariable.BranchCoverage.name())), 0.0);
assertEquals(0.8, Double.valueOf(CsvJUnitData.getValue(rows, RuntimeVariable.LineCoverage.name())), 0.0);
assertEquals("10111", CsvJUnitData.getValue(rows, RuntimeVariable.BranchCoverageBitString.name()));
assertEquals("01111", CsvJUnitData.getValue(rows, RuntimeVariable.LineCoverageBitString.name()));
}
use of org.evosuite.statistics.SearchStatistics in project evosuite by EvoSuite.
the class CoverageAnalysisOfProjectSystemTest method testMoreThanOneClassMoreThanOneCriterion.
@Test
public void testMoreThanOneClassMoreThanOneCriterion() throws IOException {
createFakeProject();
EvoSuite evosuite = new EvoSuite();
Properties.CRITERION = new Properties.Criterion[] { Properties.Criterion.BRANCH, 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
assertTrue(rows.size() == 8);
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.45, Double.valueOf(coverages.get(0)), 0.01);
// assertEquals(0.47, Double.valueOf(coverages.get(1)), 0.01);
// assertEquals(0.52, Double.valueOf(coverages.get(2)), 0.01);
// assertEquals(0.58, Double.valueOf(coverages.get(3)), 0.02);
// assertEquals(0.88, Double.valueOf(coverages.get(4)), 0.01);
// assertEquals(1.00, Double.valueOf(coverages.get(5)), 0.00);
// assertEquals(1.00, Double.valueOf(coverages.get(6)), 0.00);
assertTrue(Double.valueOf(coverages.get(0)) > 0.0);
assertTrue(Double.valueOf(coverages.get(1)) > 0.0);
assertTrue(Double.valueOf(coverages.get(2)) > 0.0);
assertTrue(Double.valueOf(coverages.get(3)) > 0.0);
assertTrue(Double.valueOf(coverages.get(4)) > 0.0);
assertTrue(Double.valueOf(coverages.get(5)) > 0.0);
assertTrue(Double.valueOf(coverages.get(6)) > 0.0);
}
Aggregations