FileDocCategorySizeDatePackage
JUnitReportTest.javaAPI DocApache Ant 1.7010092Wed Dec 13 06:16:22 GMT 2006org.apache.tools.ant.taskdefs.optional.junit

JUnitReportTest

public class JUnitReportTest extends org.apache.tools.ant.BuildFileTest
Small testcase for the junitreporttask. First test added to reproduce an fault, still a lot to improve

Fields Summary
Constructors Summary
public JUnitReportTest(String name)

        super(name);
    
Methods Summary
public voidassertIndexCreated()

        if (!new File(System.getProperty("root"),
                "src/etc/testcases/taskdefs/optional/junitreport/test/html/index.html").exists()) {
            fail("No file index file found");
        }

    
private voidexpectReportWithText(java.lang.String targetName, java.lang.String text)
run a target, assert the index file is there, look for text in the log

param
targetName target
param
text optional text to look for

        executeTarget(targetName);
        assertIndexCreated();
        if(text!=null) {
            assertLogContaining(text);
        }
    
protected voidsetUp()

        configureProject("src/etc/testcases/taskdefs/optional/junitreport.xml");
    
protected voidtearDown()

        executeTarget("clean");
    
public voidtestEmptyFile()

        expectReportWithText("testEmptyFile",
                XMLResultAggregator.WARNING_EMPTY_FILE);
    
public voidtestIncompleteFile()

        expectReportWithText("testIncompleteFile",
                XMLResultAggregator.WARNING_IS_POSSIBLY_CORRUPTED);
    
public voidtestNoFileJUnitNoFrames()
Verifies that no empty junit-noframes.html is generated when frames output is selected via the default. Needs reports1 task from junitreport.xml.

        executeTarget("reports1");
        if (new File(System.getProperty("root"), "src/etc/testcases/taskdefs/optional/junitreport/test/html/junit-noframes.html").exists())
        {
            fail("No file junit-noframes.html expected");
        }
    
public voidtestNoFrames()

        executeTarget("testNoFrames");
        File reportFile = new File(System.getProperty("root"), "src/etc/testcases/taskdefs/optional/junitreport/test/html/junit-noframes.html");
        // tests one the file object
        assertTrue("No junit-noframes.html present. Not generated?", reportFile.exists() );
        assertTrue("Cant read the report file.", reportFile.canRead() );
        assertTrue("File shouldnt be empty.", reportFile.length() > 0 );
        // conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report
        URL reportUrl = new URL( FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath()) );
        InputStream reportStream = reportUrl.openStream();
        assertTrue("This shouldnt be an empty stream.", reportStream.available() > 0);
    
public voidtestSpecialSignsInHtmlPath()

        executeTarget("testSpecialSignsInHtmlPath");
        File reportFile = new File(System.getProperty("root"), "src/etc/testcases/taskdefs/optional/junitreport/test/html# $%\u00A7&-!report/index.html");
        // tests one the file object
        assertTrue("No index.html present. Not generated?", reportFile.exists() );
        assertTrue("Cant read the report file.", reportFile.canRead() );
        assertTrue("File shouldnt be empty.", reportFile.length() > 0 );
        // conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report
        URL reportUrl = new URL( FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath()) );
        InputStream reportStream = reportUrl.openStream();
        assertTrue("This shouldnt be an empty stream.", reportStream.available() > 0);
    
public voidtestSpecialSignsInSrcPath()

        executeTarget("testSpecialSignsInSrcPath");
        File reportFile = new File(System.getProperty("root"), "src/etc/testcases/taskdefs/optional/junitreport/test/html/index.html");
        // tests one the file object
        assertTrue("No index.html present. Not generated?", reportFile.exists() );
        assertTrue("Cant read the report file.", reportFile.canRead() );
        assertTrue("File shouldnt be empty.", reportFile.length() > 0 );
        // conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report
        URL reportUrl = new URL( FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath()) );
        InputStream reportStream = reportUrl.openStream();
        assertTrue("This shouldnt be an empty stream.", reportStream.available() > 0);
    
public voidtestStackTraceLineBreaks()

        expectReportWithText("testStackTraceLineBreaks", null);
        FileReader r = null;
        try {
            r = new FileReader(new File(System.getProperty("root"),
                                        "src/etc/testcases/taskdefs/optional/junitreport/test/html/sampleproject/coins/0_CoinTest.html"));
            String report = FileUtils.readFully(r);
            assertTrue("output must contain <br>",
                       report.indexOf("junit.framework.AssertionFailedError: DOEG<br/>")
                   > -1);
        } finally {
            FileUtils.close(r);
        }
    
public voidtestWithParams()

        expectLogContaining("testWithParams", "key1=value1,key2=value2");
        File reportFile = new File(System.getProperty("root"), "src/etc/testcases/taskdefs/optional/junitreport/test/html/index.html");
        // tests one the file object
        assertTrue("No index.html present. Not generated?", reportFile.exists() );
        assertTrue("Cant read the report file.", reportFile.canRead() );
        assertTrue("File shouldnt be empty.", reportFile.length() > 0 );
        // conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report
        URL reportUrl = new URL( FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath()) );
        InputStream reportStream = reportUrl.openStream();
        assertTrue("This shouldnt be an empty stream.", reportStream.available() > 0);
    
public voidtestWithStyleFromClasspath()

        executeTarget("testWithStyleFromClasspath");
        File reportFile = new File(System.getProperty("root"), "src/etc/testcases/taskdefs/optional/junitreport/test/html/index.html");
        // tests one the file object
        assertTrue("No index.html present. Not generated?", reportFile.exists() );
        assertTrue("Cant read the report file.", reportFile.canRead() );
        assertTrue("File shouldnt be empty.", reportFile.length() > 0 );
        // conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report
        URL reportUrl = new URL( FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath()) );
        InputStream reportStream = reportUrl.openStream();
        assertTrue("This shouldnt be an empty stream.", reportStream.available() > 0);
    
public voidtestWithStyleFromDir()

        executeTarget("testWithStyleFromDir");
        File reportFile = new File(System.getProperty("root"), "src/etc/testcases/taskdefs/optional/junitreport/test/html/index.html");
        // tests one the file object
        assertTrue("No index.html present. Not generated?", reportFile.exists() );
        assertTrue("Cant read the report file.", reportFile.canRead() );
        assertTrue("File shouldnt be empty.", reportFile.length() > 0 );
        // conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report
        URL reportUrl = new URL( FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath()) );
        InputStream reportStream = reportUrl.openStream();
        assertTrue("This shouldnt be an empty stream.", reportStream.available() > 0);
    
public voidtestWithStyleFromDirAndXslImport()

        executeTarget("testWithStyleFromDirAndXslImport");
        File reportFile = new File(System.getProperty("root"), "src/etc/testcases/taskdefs/optional/junitreport/test/html/index.html");
        // tests one the file object
        assertTrue("No index.html present. Not generated?", reportFile.exists() );
        assertTrue("Cant read the report file.", reportFile.canRead() );
        assertTrue("File shouldnt be empty.", reportFile.length() > 0 );
        // conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report
        URL reportUrl = new URL( FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath()) );
        InputStream reportStream = reportUrl.openStream();
        assertTrue("This shouldnt be an empty stream.", reportStream.available() > 0);
    
public voidtestWrongElement()

        expectReportWithText("testWrongElement",
                XMLResultAggregator.WARNING_INVALID_ROOT_ELEMENT);