use of org.evosuite.statistics.OutputVariable in project evosuite by EvoSuite.
the class ImplicitExplicitExceptionsSystemTest method testExceptionFitness.
private void testExceptionFitness() {
EvoSuite evosuite = new EvoSuite();
String targetClass = ImplicitExplicitException.class.getCanonicalName();
Properties.TARGET_CLASS = targetClass;
Properties.CRITERION = new Criterion[] { Properties.Criterion.EXCEPTION };
Properties.OUTPUT_VARIABLES = "" + RuntimeVariable.Explicit_MethodExceptions + "," + RuntimeVariable.Explicit_TypeExceptions + "," + RuntimeVariable.Implicit_MethodExceptions + "," + RuntimeVariable.Implicit_TypeExceptions;
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 fitness = best.getFitness();
/*
* there are 2 undeclared exceptions (both implicit and explicit),
* and 3 declared: so fit = 1 / (1+5)
*/
Assert.assertEquals("Wrong fitness: ", 1d / 6d, fitness, 0.0000001);
Map<String, OutputVariable<?>> map = DebugStatisticsBackend.getLatestWritten();
Assert.assertNotNull(map);
Assert.assertEquals(1, map.get(RuntimeVariable.Explicit_MethodExceptions.toString()).getValue());
Assert.assertEquals(1, map.get(RuntimeVariable.Explicit_TypeExceptions.toString()).getValue());
Assert.assertEquals(1, map.get(RuntimeVariable.Implicit_MethodExceptions.toString()).getValue());
Assert.assertEquals(1, map.get(RuntimeVariable.Implicit_TypeExceptions.toString()).getValue());
}
use of org.evosuite.statistics.OutputVariable in project evosuite by EvoSuite.
the class CoverageAnalysisCharSequenceSystemTest method test.
@Test
public void test() throws IOException {
EvoSuite evosuite = new EvoSuite();
String targetClass = WordUtils.class.getCanonicalName();
String testClass = WordUtilsTest.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;
Properties.SANDBOX = false;
Properties.VIRTUAL_FS = false;
Properties.VIRTUAL_NET = false;
Properties.REPLACE_CALLS = false;
Properties.REPLACE_SYSTEM_IN = false;
Properties.MAX_LOOP_ITERATIONS = -1;
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(10, (Integer) outputVariables.get(RuntimeVariable.Total_Goals.name()).getValue(), 0.0);
assertEquals(9, (Integer) outputVariables.get(RuntimeVariable.Covered_Goals.name()).getValue(), 0.0);
assertEquals(0.9, (Double) outputVariables.get(RuntimeVariable.LineCoverage.name()).getValue(), 0.0);
assertEquals(1, (Integer) outputVariables.get(RuntimeVariable.Tests_Executed.name()).getValue(), 0.0);
// the constructor of 'WordUtils' is not covered
assertEquals("0111111111", (String) outputVariables.get(RuntimeVariable.LineCoverageBitString.name()).getValue());
// 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());
// all components except the WordUtils' constructor are covered ("1"), and the test case passes ("+")
assertTrue(lines.get(0).equals("0 1 1 1 1 1 1 1 1 1 +"));
}
use of org.evosuite.statistics.OutputVariable in project evosuite by EvoSuite.
the class CoverageAnalysisLocaleSystemTest method test.
@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(10, (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 / 10.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 + 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());
// all components have been covered ("1"), and the test case pass ("+")
assertTrue(lines.get(0).contains("+"));
}
use of org.evosuite.statistics.OutputVariable in project evosuite by EvoSuite.
the class CoverageAnalysisStringInstrumentationSystemTest method testCreateBigInteger.
@Test
public void testCreateBigInteger() throws IOException {
EvoSuite evosuite = new EvoSuite();
String targetClass = ClassNumberUtils.class.getCanonicalName();
String testClass = ClassNumberUtilsTest.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(20, (Integer) outputVariables.get(RuntimeVariable.Total_Goals.name()).getValue(), 0.0);
assertEquals(19, (Integer) outputVariables.get(RuntimeVariable.Covered_Goals.name()).getValue(), 0.0);
assertEquals(0.95, (Double) outputVariables.get(RuntimeVariable.LineCoverage.name()).getValue(), 0.0);
assertEquals(1, (Integer) outputVariables.get(RuntimeVariable.Tests_Executed.name()).getValue(), 0.0);
assertEquals("01111111111111111111", (String) outputVariables.get(RuntimeVariable.LineCoverageBitString.name()).getValue());
// 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());
// all components have been covered ("1"), and the test case pass ("+")
assertEquals("0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 +", lines.get(0));
}
use of org.evosuite.statistics.OutputVariable in project evosuite by EvoSuite.
the class CoverageAnalysisWithRefectionSystemTest method testBindFilteredEventsToMethod.
@Test
public void testBindFilteredEventsToMethod() throws IOException {
EvoSuite evosuite = new EvoSuite();
String targetClass = ClassPublicInterface.class.getCanonicalName();
String testClass = ClassPublicInterfaceTest.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();
// The number of lines seems to be different depending on the compiler
assertTrue(27 - ((Integer) outputVariables.get(RuntimeVariable.Total_Goals.name()).getValue()) <= 1);
assertTrue(11 - ((Integer) outputVariables.get(RuntimeVariable.Covered_Goals.name()).getValue()) <= 1);
assertEquals(1, (Integer) outputVariables.get(RuntimeVariable.Tests_Executed.name()).getValue(), 0.0);
// 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);
assertTrue(lines.get(0).replace(" ", "").endsWith("+"));
}
Aggregations