protected Object getOutputVariableValue(Map<String, OutputVariable<?>> data, String key) { OutputVariable<?> ov = data.get(key); return (ov != null) ? ov.getValue() : null; }
@Override public void writeData(Chromosome result, Map<String, OutputVariable<?>> data) { for(OutputVariable<?> var : data.values()) { if (System.out!=null) { System.out.println(var.getName()+": "+var.getValue()); } } }
private static Integer getIntegerValue(Map<String,OutputVariable<?>> map, RuntimeVariable variable){ OutputVariable<?> out = map.get(variable.toString()); if( out != null){ return (Integer) out.getValue(); } else { return null; } }
private static Double getDoubleValue(Map<String,OutputVariable<?>> map, RuntimeVariable variable){ OutputVariable<?> out = map.get(variable.toString()); if( out != null){ return (Double) out.getValue(); } else { return null; } } };
/** * Retrieve one line of data * @param data * @return */ private String getCSVData(Map<String, OutputVariable<?>> data) { StringBuilder r = new StringBuilder(); Iterator<Entry<String, OutputVariable<?>>> it = data.entrySet().iterator(); while (it.hasNext()) { Entry<String, OutputVariable<?>> e = (Entry<String, OutputVariable<?>>)it.next(); r.append(e.getValue().getValue()); if (it.hasNext()) r.append(","); } return r.toString(); }
@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 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 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); } }
private void testCoverageIssue(){ Properties.COVERAGE = true; Properties.OUTPUT_VARIABLES = ""+RuntimeVariable.LineCoverage; do100percentLineTestOnStandardCriteria(CoverageIssue.class); OutputVariable out = getOutputVariable(RuntimeVariable.LineCoverage); double lineCov = (Double) out.getValue(); assertEquals(1d, lineCov, 0.01); }
protected void checkUnstable() throws IllegalStateException{ OutputVariable unstable = getOutputVariable(RuntimeVariable.HadUnstableTests); Assert.assertNotNull(unstable); Assert.assertEquals(Boolean.FALSE, unstable.getValue()); }
@Test public void testHandlingOfNoThreads(){ EvoSuite evosuite = new EvoSuite(); String targetClass = NoThreads.class.getCanonicalName(); Properties.TARGET_CLASS = targetClass; Properties.SANDBOX = true; Properties.OUTPUT_VARIABLES=""+RuntimeVariable.Threads; String[] command = new String[] { "-generateSuite", "-class", targetClass }; evosuite.parseCommandLine(command); Map<String, OutputVariable<?>> map = DebugStatisticsBackend.getLatestWritten(); Assert.assertNotNull(map); OutputVariable<?> threads = map.get(RuntimeVariable.Threads.toString()); Assert.assertNotNull(threads); Assert.assertEquals(1, threads.getValue()); }
@Test public void testFloatDefault() { EvoSuite evosuite = new EvoSuite(); String targetClass = FloatArrayDefault.class.getCanonicalName(); Properties.TARGET_CLASS = targetClass; Properties.OUTPUT_VARIABLES=""+RuntimeVariable.HadUnstableTests; 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); Map<String, OutputVariable<?>> map = DebugStatisticsBackend.getLatestWritten(); Assert.assertNotNull(map); OutputVariable unstable = map.get(RuntimeVariable.HadUnstableTests.toString()); Assert.assertNotNull(unstable); Assert.assertEquals(Boolean.FALSE, unstable.getValue()); }
@Test public void testOverload() { EvoSuite evosuite = new EvoSuite(); String targetClass = Overload.class.getCanonicalName(); Properties.TARGET_CLASS = targetClass; Properties.OUTPUT_VARIABLES=""+RuntimeVariable.HadUnstableTests; 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); Map<String, OutputVariable<?>> map = DebugStatisticsBackend.getLatestWritten(); Assert.assertNotNull(map); OutputVariable<?> unstable = map.get(RuntimeVariable.HadUnstableTests.toString()); Assert.assertNotNull(unstable); Assert.assertEquals(Boolean.FALSE, unstable.getValue()); }
@Test public void testRuntimeUser() { EvoSuite evosuite = new EvoSuite(); String targetClass = RuntimeUser.class.getCanonicalName(); Properties.TARGET_CLASS = targetClass; Properties.OUTPUT_VARIABLES=""+RuntimeVariable.HadUnstableTests; 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); Map<String, OutputVariable<?>> map = DebugStatisticsBackend.getLatestWritten(); Assert.assertNotNull(map); OutputVariable unstable = map.get(RuntimeVariable.HadUnstableTests.toString()); Assert.assertNotNull(unstable); Assert.assertEquals(Boolean.FALSE, unstable.getValue()); }
@Test public void testRuntimeUser() { EvoSuite evosuite = new EvoSuite(); String targetClass = ExitVM.class.getCanonicalName(); Properties.TARGET_CLASS = targetClass; Properties.OUTPUT_VARIABLES=""+RuntimeVariable.HadUnstableTests; 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); Map<String, OutputVariable<?>> map = DebugStatisticsBackend.getLatestWritten(); Assert.assertNotNull(map); OutputVariable unstable = map.get(RuntimeVariable.HadUnstableTests.toString()); Assert.assertNotNull(unstable); Assert.assertEquals(Boolean.FALSE, unstable.getValue()); }
@Test public void testObjectDefault() { EvoSuite evosuite = new EvoSuite(); String targetClass = ObjectArrayDefault.class.getCanonicalName(); Properties.TARGET_CLASS = targetClass; Properties.OUTPUT_VARIABLES=""+RuntimeVariable.HadUnstableTests; 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); Map<String, OutputVariable<?>> map = DebugStatisticsBackend.getLatestWritten(); Assert.assertNotNull(map); OutputVariable unstable = map.get(RuntimeVariable.HadUnstableTests.toString()); Assert.assertNotNull(unstable); Assert.assertEquals(Boolean.FALSE, unstable.getValue()); }