Reputation: 2677
I want to show some data in my GUI from my tests. I'm using JUnit 3 because other applications that I use are using that one. So if I use JUnit 4 it will collapse. I know that the possibilities in JUnit 4 are much bigger en better. But I can't use that, So I have some questions:
I know you can get some data from the JUnit 3 tests, but some data I can't find: - How can I get the runtime of each/all tests? - How can I get the testname of the each test that failes? - How can I get the testnames of each test that was correct?
I looked in this API, but I can find it: http://www.junit.org/junit/javadoc/3.8.1/
I use JUnit 3.8.2, but couldn't find that API.
Upvotes: 1
Views: 283
Reputation: 2677
I used the ant.jar library To create a report from the Junit tests. First I set the Task and specify the properties how I want the test. And then I create the formatter witch i set to XML, So I get the XML output of the JUnit test.
Then I put the Test (in this case AllTests.class) to the Task and Execute it. And Voila I can find the report in the directory that I set in test.setTodir(.....)
Project project = new Project();
JUnitTask task;
try {
task = new JUnitTask();
project.setProperty("java.io.tmpdir","C:\\Reports\\XMLS"); //set temporary directory
task.setProject(project);
JUnitTask.SummaryAttribute sa = new JUnitTask.SummaryAttribute();
sa.setValue("withOutAndErr");
task.setFork(false);
task.setPrintsummary(sa);
Logger.info(getClass(), task.toString());
FormatterElement formater = new FormatterElement();
FormatterElement.TypeAttribute type = new FormatterElement.TypeAttribute();
type.setValue("xml");
formater.setType(type);
task.addFormatter(formater);
JUnitTest test = new JUnitTest(AllTests.class.getName());
test.setTodir(new File("C:\\Reports\\XMLS"));
task.addTest(test);
task.execute();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Upvotes: 1