aspose file tools*
The moose likes Testing and the fly likes generate junit reports Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "generate junit reports" Watch "generate junit reports" New topic
Author

generate junit reports

hadas yaari
Greenhorn

Joined: Dec 26, 2008
Posts: 11
Hello everybody,
I am new in junit and I would like to generate a very simple report of how many tests succeeded, how failed and the name of the tests that succeeded and failed.
It's a part of a plug in that we create and I want it to happen when the user run the tests (I don't want to run them myself).
Also it mustn't be a report - If I have another way to collect the information it would be fine.

Thank you very much
hadas
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30758
    
156

Hadas,
Welcome to JavaRanch!

If you can use Ant to run JUnit, the JUnit report task generates a nice HTML report. If not, you could write your own JUnit test runner and hook into JUnit directly to get the data.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
hadas yaari
Greenhorn

Joined: Dec 26, 2008
Posts: 11
Hi Jeanne, thanks for the quick response.
I don't want to build a runner because I want the user not to change his work ways.
I don't know the ANT - can I tell him to generate the report by programing (in the java code)?
I thought maybe I could add a listener that after every test will get somehow the results of the tests. Is it possible?
I'm looking for a very simple way to implement it.
This is a project for the university and we are creating a plug-in that his goal is to improve the programmer development environment when the compnay has several sites all around the world. So in addition to other information that we want to send to the next site in the end of workday, we want to send also a test report.

I would be happy if someone would lead me to the way to implement it.
Thank you very much
Hadas
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
A plug-in - for what? That is, what would you plug it in to, and how?

See whether http://junit.sourceforge.net/javadoc/org/junit/runner/notification/RunListener.html helps you...


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
hadas yaari
Greenhorn

Joined: Dec 26, 2008
Posts: 11
Hi Ilja,
Thanks - this was very helpfull and I think I will use it.
The problem is that I will have to run the test by myself and not in the custom way (right button on the test -> run/debug).
Is there another way?
Hadas
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30758
    
156

Originally posted by hadas yaari:
The problem is that I will have to run the test by myself and not in the custom way (right button on the test -> run/debug).
Is there another way?

You could write/modify an IDE plugin to hook into the default one. This is why Ilja asked how you were running it.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by hadas yaari:

The problem is that I will have to run the test by myself and not in the custom way (right button on the test -> run/debug).
Is there another way?


Sounds like you are using some kind of IDE? Which one?
hadas yaari
Greenhorn

Joined: Dec 26, 2008
Posts: 11
Hi Ilja,
I am using Eclipse
Thanks, Hadas
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Well, as Jeanne already hinted at, you could probably write an Eclipse plugin that does this.

Are you sure that running the tests from the IDE is the best idea? It sounds a bit like what you want to do might be better done using a continuous integration server, like Hudson or Cruise Control.
hadas yaari
Greenhorn

Joined: Dec 26, 2008
Posts: 11
Hi Ilja,
Thats exactly what I want - I want to add to my plugin the possibility to trac the test results and create a report acording to it.
Now I can trac the result of the unit tests that I run manually (by org.junit.runner.notification.RunListener after creating a new JUnitCore)
Is there any API I can use in order to get the wanted intformation?
Thanks
Dan Birsan
Greenhorn

Joined: Dec 03, 2011
Posts: 1
<target name="SoapUITest">
<mkdir dir="${junit.output.dir}"/>
<junit fork="yes" printsummary="withOutAndErr">
<formatter type="xml"/>
<test name="soapUITest" todir="${junit.output.dir}"/>
<classpath refid="automation.classpath"/>
</junit>
</target>

You can run from ANT the test you mentioned and a report is generated automatically by ANT and JUnit.
soapUITest represents the class you are running as a test,

Hope this helps
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: generate junit reports