use of org.evosuite.testcase.TestCase in project evosuite by EvoSuite.
the class MockJOptionPaneShowMessageDialogTest method testShowMessageDialog0.
@Test
public void testShowMessageDialog0() throws Exception {
TestSuiteChromosome suite = new TestSuiteChromosome();
InstrumentingClassLoader cl = new InstrumentingClassLoader();
TestCase t0 = buildTestCase0TrueBranch(cl);
TestCase t1 = buildTestCase0FalseBranch(cl);
suite.addTest(t0);
suite.addTest(t1);
BranchCoverageSuiteFitness ff = new BranchCoverageSuiteFitness(cl);
ff.getFitness(suite);
Set<TestFitnessFunction> coveredGoals = suite.getCoveredGoals();
Assert.assertEquals(3, coveredGoals.size());
}
use of org.evosuite.testcase.TestCase in project evosuite by EvoSuite.
the class MockJOptionPaneShowMessageDialogTest method testShowMessageDialog2.
@Test
public void testShowMessageDialog2() throws Exception {
TestSuiteChromosome suite = new TestSuiteChromosome();
InstrumentingClassLoader cl = new InstrumentingClassLoader();
TestCase t0 = buildTestCase2TrueBranch(cl);
TestCase t1 = buildTestCase2FalseBranch(cl);
suite.addTest(t0);
suite.addTest(t1);
BranchCoverageSuiteFitness ff = new BranchCoverageSuiteFitness(cl);
ff.getFitness(suite);
Set<TestFitnessFunction> coveredGoals = suite.getCoveredGoals();
Assert.assertEquals(3, coveredGoals.size());
}
use of org.evosuite.testcase.TestCase in project evosuite by EvoSuite.
the class MockJOptionPaneTest method testShowInputDialogWasFound.
@Test
public void testShowInputDialogWasFound() throws Exception {
boolean hasStringDialog0 = JOptionPaneInputs.getInstance().hasDialog(GUIAction.STRING_INPUT);
assertFalse(hasStringDialog0);
InstrumentingClassLoader cl = new InstrumentingClassLoader();
TestCase t1 = buildTestCase0(cl);
TestCaseExecutor.getInstance().execute(t1);
boolean hasStringDialog = JOptionPaneInputs.getInstance().hasDialog(GUIAction.STRING_INPUT);
assertTrue(hasStringDialog);
}
use of org.evosuite.testcase.TestCase in project evosuite by EvoSuite.
the class MockJOptionPaneTest method testInlinerBug.
@Test
public void testInlinerBug() throws Exception {
Properties.TIMEOUT = Integer.MAX_VALUE;
InstrumentingClassLoader cl = new InstrumentingClassLoader();
TestCase t0 = buildTestCase0(cl);
TestCase t1 = buildTestCase1(cl);
TestSuiteChromosome suite = new TestSuiteChromosome();
suite.addTest(t0);
suite.addTest(t1);
System.out.println(suite.toString());
BranchCoverageSuiteFitness ff = new BranchCoverageSuiteFitness(cl);
ff.getFitness(suite);
ConstantInliner inliner = new ConstantInliner();
inliner.inline(suite);
System.out.println(suite.toString());
List<ExecutionResult> execResults = suite.getLastExecutionResults();
assertEquals(2, execResults.size());
ExecutionResult r1 = execResults.get(0);
ExecutionResult r2 = execResults.get(1);
r1.calledReflection();
r2.calledReflection();
}
use of org.evosuite.testcase.TestCase 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