/** * Shorthand for getOutputVariables(individual, false) */ private Map<String, OutputVariable<?>> getOutputVariables(TestSuiteChromosome individual) { return getOutputVariables(individual, false); }
/** * Write result to disk using selected backend * * @return true if the writing was successful */ public boolean writeStatisticsForAnalysis() { logger.info("Writing statistics"); if(backend == null) { LoggingUtils.getEvoLogger().info("Backend is null"); return false; } outputVariables.put(RuntimeVariable.Total_Time.name(), new OutputVariable<Object>(RuntimeVariable.Total_Time.name(), System.currentTimeMillis() - startTime)); TestSuiteChromosome individual = new TestSuiteChromosome(); Map<String,OutputVariable<?>> map = getOutputVariables(individual); if(map==null){ logger.error("Not going to write down statistics data, as some are missing"); return false; } boolean valid = RuntimeVariable.validateRuntimeVariables(map); if(!valid){ logger.error("Not going to write down statistics data, as some data is invalid"); return false; } else { backend.writeData(individual, map); return true; } }
@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); }
@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); }
@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); }
@Test public void testRhoCoverage() { SearchStatistics statistics = this.aux(new Properties.Criterion[] { Properties.Criterion.RHO }); 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); }
@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); }
@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); }
@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); } }
@Test public void testPublicStaticField() { EvoSuite evosuite = new EvoSuite(); String targetClass = Days.class.getCanonicalName(); // Test suite with private static field. String testClass = TestDaysWithPublicField.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); }
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());
@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); }
Assert.assertNotNull(statistics); Map<String, OutputVariable<?>> outputVariables = statistics.getOutputVariables();
@Test public void testOneFitnessFunction() { EvoSuite evosuite = new EvoSuite(); String targetClass = Euclidean.class.getCanonicalName(); Properties.TARGET_CLASS = targetClass; Properties.CRITERION = new Criterion[] { Criterion.BRANCH }; String[] command = new String[] { "-class", targetClass, "-Djunit=" + targetClass + Properties.JUNIT_SUFFIX, "-measureCoverage" }; SearchStatistics statistics = (SearchStatistics) evosuite.parseCommandLine(command); Assert.assertNotNull(statistics); Map<String, OutputVariable<?>> data = statistics.getOutputVariables(); assertEquals(5, (Integer) data.get("Total_Goals").getValue(), 0.0); assertEquals(5, (Integer) data.get("Covered_Goals").getValue(), 0.0); } }
@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); }
@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); }
Assert.assertNotNull(statistics); Map<String, OutputVariable<?>> outputVariables = statistics.getOutputVariables();
Assert.assertNotNull(statistics); Map<String, OutputVariable<?>> outputVariables = statistics.getOutputVariables();
@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()); }
Assert.assertNotNull(statistics); Map<String, OutputVariable<?>> outputVariables = statistics.getOutputVariables();