Search in sources :

Example 76 with TestCase

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());
}
Also used : TestCase(org.evosuite.testcase.TestCase) TestFitnessFunction(org.evosuite.testcase.TestFitnessFunction) BranchCoverageSuiteFitness(org.evosuite.coverage.branch.BranchCoverageSuiteFitness) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) InstrumentingClassLoader(org.evosuite.instrumentation.InstrumentingClassLoader) Test(org.junit.Test)

Example 77 with TestCase

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());
}
Also used : TestCase(org.evosuite.testcase.TestCase) TestFitnessFunction(org.evosuite.testcase.TestFitnessFunction) BranchCoverageSuiteFitness(org.evosuite.coverage.branch.BranchCoverageSuiteFitness) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) InstrumentingClassLoader(org.evosuite.instrumentation.InstrumentingClassLoader) Test(org.junit.Test)

Example 78 with TestCase

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);
}
Also used : TestCase(org.evosuite.testcase.TestCase) InstrumentingClassLoader(org.evosuite.instrumentation.InstrumentingClassLoader) Test(org.junit.Test)

Example 79 with TestCase

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();
}
Also used : ConstantInliner(org.evosuite.testcase.ConstantInliner) TestCase(org.evosuite.testcase.TestCase) BranchCoverageSuiteFitness(org.evosuite.coverage.branch.BranchCoverageSuiteFitness) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) ExecutionResult(org.evosuite.testcase.execution.ExecutionResult) InstrumentingClassLoader(org.evosuite.instrumentation.InstrumentingClassLoader) Test(org.junit.Test)

Example 80 with TestCase

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;
}
Also used : IOException(java.io.IOException) TestCase(org.evosuite.testcase.TestCase) TestChromosome(org.evosuite.testcase.TestChromosome) File(java.io.File)

Aggregations

TestCase (org.evosuite.testcase.TestCase)192 Test (org.junit.Test)119 DefaultTestCase (org.evosuite.testcase.DefaultTestCase)90 ArrayList (java.util.ArrayList)67 CoverageGoalTestNameGenerationStrategy (org.evosuite.junit.naming.methods.CoverageGoalTestNameGenerationStrategy)47 MethodCoverageTestFitness (org.evosuite.coverage.method.MethodCoverageTestFitness)45 TestSuiteChromosome (org.evosuite.testsuite.TestSuiteChromosome)43 IntPrimitiveStatement (org.evosuite.testcase.statements.numeric.IntPrimitiveStatement)39 VariableReference (org.evosuite.testcase.variable.VariableReference)26 OutputCoverageGoal (org.evosuite.coverage.io.output.OutputCoverageGoal)25 OutputCoverageTestFitness (org.evosuite.coverage.io.output.OutputCoverageTestFitness)25 TestFitnessFunction (org.evosuite.testcase.TestFitnessFunction)24 BranchCoverageSuiteFitness (org.evosuite.coverage.branch.BranchCoverageSuiteFitness)17 TestChromosome (org.evosuite.testcase.TestChromosome)17 InstrumentingClassLoader (org.evosuite.instrumentation.InstrumentingClassLoader)15 Ignore (org.junit.Ignore)15 VariableReferenceImpl (org.evosuite.testcase.variable.VariableReferenceImpl)14 GenericMethod (org.evosuite.utils.generic.GenericMethod)12 ExceptionCoverageTestFitness (org.evosuite.coverage.exception.ExceptionCoverageTestFitness)11 InputCoverageGoal (org.evosuite.coverage.io.input.InputCoverageGoal)10