E.S.
E.S.

Reputation: 2841

Creating a Java reporting project -- would like to use JUnit and Ant but not sure how

I'm interested in generating reports for a certain group of (non-software) engineers in my company using JUnit. Unlike typical JUnit testing where you are ensuring objects, methods, etc are bug free, I want to use JUnit to confirm if results in large log files are within range and give reports on it.

My background: Experienced with Java. I am familiar with JUnit 4, I have spent the last hour or 2 looking through ANT documentation and I think I have a strong idea how it works (I just don't know all the XML commands), and I use Eclipse religiously. Specifically Eclipse June (latest).

My goal is to create a slew of testcases that assert if the values in the logs are within the right range. The test class can then be run over and over on every single log file. After each run, the results will be added to an HTML file.

I am aware of the JUnit Report features in Ant but I am having a lot of trouble putting all the pieces of the puzzle together properly. I know I can hack my way through this project quite easily, but I want to do this the right way.

Can any point me in the right direction in how to:

code:

public static void main(String[] args) {
    JUnitCore junit = new JUnitCore();
    RunListener listener = new RunListener();
    junit.addListener(listener);
    Result result = junit.run(GearAndBrakeFaultLogReports.class);
    for (Failure f : result.getFailures()) {
        System.out.println(f.toString());
        System.out.println(f.getDescription());
        System.out.println(f.getTestHeader());
        System.out.println(f.getException());
        System.out.println(f.getMessage());
    }
    System.out.println("Done.");
}

I imagine I will have more questions as this project develops, but I think getting over the initial hump will be very good for me! I know there are a lot of questions, so any help and I'll gladly point bump :) My hope is, someone familiar with these tools can answer all these with a matter of pointing me to web sites, functions, or an example project that does a similar thing.

Upvotes: 0

Views: 1447

Answers (1)

user1024314
user1024314

Reputation:

For creating a PDF from JUnit test results: http://junitpdfreport.sourceforge.net/managedcontent/

As a unit testing frameword, JUnit reports are very specific to software engineering. Although, you might be able to customize it for a non-unit testing scenario, it will take a lot of customizing. Unlike other testing frameworks (such as TestNG) JUnit doesn't provide the ability to make your own report generator. TestNG, however, can be used to run JUnit tests and even produces a JUnit report in addition to its own reports. TestNG can run your JUnit tests and then create custom reports by providing a custom implementation of the org.testng.IReporter interface.

http://testng.org/doc/documentation-main.html

Having written reports in Java for many years now, I would strongly recommend trying out a reporting tool such as JasperReports and the iReport tool. Jasper Reports can process custom data sources such as your log files and produce reports in many formats, including XML, HTML, and PDF.

http://community.jaspersoft.com/project/ireport-designer

Upvotes: 1

Related Questions