use of org.evosuite.testcase.TestChromosome in project evosuite by EvoSuite.
the class AbstractFitnessFactory method getFitness.
/**
* {@inheritDoc}
*/
@Override
public double getFitness(TestSuiteChromosome suite) {
ExecutionTracer.enableTraceCalls();
int coveredGoals = 0;
for (T goal : getCoverageGoals()) {
for (TestChromosome test : suite.getTestChromosomes()) {
if (goal.isCovered(test)) {
coveredGoals++;
break;
}
}
}
ExecutionTracer.disableTraceCalls();
return getCoverageGoals().size() - coveredGoals;
}
use of org.evosuite.testcase.TestChromosome in project evosuite by EvoSuite.
the class TestSuiteChromosome method addTest.
/**
* Add a test to a test suite
*
* @param test
* a {@link org.evosuite.testcase.TestCase} object.
*/
public TestChromosome addTest(TestCase test) {
TestChromosome c = new TestChromosome();
c.setTestCase(test);
addTest(c);
return c;
}
use of org.evosuite.testcase.TestChromosome in project evosuite by EvoSuite.
the class TestSuiteChromosome method toString.
/**
* {@inheritDoc}
*
* Determine relative ordering of this chromosome to another chromosome If
* fitness is equal, the shorter chromosome comes first
*/
/*
* public int compareTo(Chromosome o) { if(RANK_LENGTH && getFitness() ==
* o.getFitness()) { return (int) Math.signum((length() -
* ((TestSuiteChromosome)o).length())); } else return (int)
* Math.signum(getFitness() - o.getFitness()); }
*/
@Override
public String toString() {
String result = "TestSuite: " + tests.size() + "\n";
int i = 0;
for (TestChromosome test : tests) {
result += "Test " + i + ": \n";
i++;
if (test.getLastExecutionResult() != null) {
result += test.getTestCase().toCode(test.getLastExecutionResult().exposeExceptionMapping());
} else {
result += test.getTestCase().toCode() + "\n";
}
}
return result;
}
use of org.evosuite.testcase.TestChromosome in project evosuite by EvoSuite.
the class TestSuiteChromosome method getCoveredGoals.
/**
* <p>
* getCoveredGoals
* </p>
*
* @return a {@link java.util.Set} object.
*/
public Set<TestFitnessFunction> getCoveredGoals() {
Set<TestFitnessFunction> goals = new LinkedHashSet<TestFitnessFunction>();
for (TestChromosome test : tests) {
final Set<TestFitnessFunction> goalsForTest = test.getTestCase().getCoveredGoals();
goals.addAll(goalsForTest);
}
return goals;
}
use of org.evosuite.testcase.TestChromosome in project evosuite by EvoSuite.
the class HTMLStatisticsBackend method writeRunPage.
/**
* Write a file for a particular run
*
* @param run
* a {@link org.evosuite.utils.ReportGenerator.StatisticEntry}
* object.
* @return a {@link java.lang.String} object.
*/
@SuppressWarnings("deprecation")
protected String writeRunPage(TestSuiteChromosome suite, Map<String, OutputVariable<?>> data) {
StringBuffer sb = new StringBuffer();
String className = (String) data.get("TARGET_CLASS").getValue();
writeHTMLHeader(sb, className);
sb.append("<br><br><h2 class=title>Summary</h2>\n");
sb.append("<ul><li>Target class: ");
sb.append(getOutputVariableValue(data, "TARGET_CLASS"));
sb.append(": ");
sb.append(suite.getCoverage());
sb.append("</ul>\n");
writeResultTable(suite, sb, data);
// writeMutationTable(sb);
sb.append("<div id=\"page\">\n");
sb.append("<div id=\"page-bgtop\">\n");
sb.append("<div id=\"page-bgbtm\">\n");
sb.append("<div id=\"content\">\n");
sb.append("<div id=\"post\">\n");
// Resulting test case
sb.append("<h2 class=title id=tests>Test suite</h2>\n");
sb.append("<div class=tests>\n");
int num = 0;
for (TestChromosome testChromosome : suite.getTestChromosomes()) {
TestCase test = testChromosome.getTestCase();
sb.append("<h3>Test case ");
sb.append(++num);
sb.append("</h3>\n");
/*
* if(test.exceptionThrown != null) { sb.append("<p>Raises:");
* sb.append(test.exceptionThrown); sb.append("</p>"); }
*/
sb.append("<pre class=\"prettyprint\" style=\"border: 1px solid #888;padding: 2px\">\n");
int linecount = 1;
String code = null;
if (testChromosome.getLastExecutionResult() != null) {
code = test.toCode(testChromosome.getLastExecutionResult().exposeExceptionMapping());
} else
code = test.toCode();
for (String line : code.split("\n")) {
sb.append(String.format("<span class=\"nocode\"><a name=\"%d\">%3d: </a></span>", linecount, linecount));
/*
* if(test.exceptionsThrown != null &&
* test.exception_statement == test_line)
* sb.append("<span style=\"background: #FF0000\">");
*/
sb.append(StringEscapeUtils.escapeHtml4(line));
/*
* if(test.exceptionThrown != null &&
* test.exception_statement == test_line)
* sb.append("</span>");
*/
linecount++;
sb.append("\n");
}
sb.append("</pre>\n");
}
sb.append("</div>");
sb.append("<div id=\"post\">\n");
OutputVariable<?> ov_covered_lines = data.get(RuntimeVariable.Covered_Lines.name());
@SuppressWarnings("unchecked") Set<Integer> coveredLines = (ov_covered_lines != null) ? (Set<Integer>) ov_covered_lines.getValue() : new HashSet<Integer>();
// Source code
try {
Iterable<String> source = html_analyzer.getClassContent(className);
sb.append("<h2 class=title id=source>Source Code</h2>\n");
sb.append("<div class=source>\n");
sb.append("<p>");
sb.append("<pre class=\"prettyprint\" style=\"border: 1px solid #888;padding: 2px\">");
int linecount = 1;
for (String line : source) {
sb.append(String.format("<span class=\"nocode\"><a name=\"%d\">%3d: </a></span>", linecount, linecount));
if (coveredLines.contains(linecount)) {
sb.append("<span style=\"background-color: #ffffcc\">");
sb.append(StringEscapeUtils.escapeHtml4(line));
sb.append("</span>");
} else
sb.append(StringEscapeUtils.escapeHtml4(line));
sb.append("\n");
linecount++;
}
sb.append("</pre>\n");
sb.append("</p>\n");
} catch (Exception e) {
// Don't display source if there is an error
}
sb.append("</div>\n");
sb.append("<div id=\"post\">\n");
writeParameterTable(sb, data);
sb.append("</div>\n");
sb.append("<p><br><a href=\"../report-generation.html\">Back to Overview</a></p>\n");
writeHTMLFooter(sb);
String filename = "report-" + className + "-" + getNumber(className) + ".html";
File file = new File(getReportDir().getAbsolutePath() + "/html/" + filename);
FileIOUtils.writeFile(sb.toString(), file);
// return file.getAbsolutePath();
return filename;
}
Aggregations