aspose file tools*
The moose likes Testing and the fly likes Calling all JUNIT 4 Guru Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Calling all JUNIT 4 Guru" Watch "Calling all JUNIT 4 Guru" New topic
Author

Calling all JUNIT 4 Guru

Zenikko Sugiarto
Ranch Hand

Joined: Jan 09, 2005
Posts: 58
Because I can't find any resources on the net that provides this info!

How can I create my own test runner in JUNIT to capture test result?

How can I enforce test dependencies? i.e do not bother to proceed if so and so test fails?

How can I capture the result of a running test, knowing how many methods are being run, which one successful etc.

Been looking in their web page but didn't find anything that tells me how to do this. Every single example I found on the net, repeats the same thing over and over again, that is how to use the annotations to run the test.

Haaalp!!
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30749
    
156

Originally posted by Zenikko Sugiarto:
How can I create my own test runner in JUNIT to capture test result?

cp suite is an open source test runner. I recommend taking a look at their runner class to see what needs to be implemented.


How can I enforce test dependencies? i.e do not bother to proceed if so and so test fails?

JUnit isn't designed to do this. (JUnit 3.8 didn't do it either.) While I believe that unit test dependencies are often a code smell and should be avoided, I recommend a different framework (TestNG) if this is a real requirement for you. Say if you have legacy tests with dependencies. Although in that case, I would question how you handle it now. For new code, I would try to avoid those dependencies as it makes the tests more brittle and harder to maintain.


How can I capture the result of a running test, knowing how many methods are being run, which one successful etc.

You could do this through a test runner, scanning the output of the built in text runner or running through Ant/Maven and scanning that output. Which makes the most sense depends on the context you are running the tests in.


[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
C Popp
Greenhorn

Joined: Aug 08, 2007
Posts: 14
I like to run my JUnit tests as a small application. I have result processing classes and jsp's to display results. You can use pojo's and beans for tracking different aspects of the tests being run. If you need a dependency, you can try using a hashtable or map with the key = testname and value = pass/fail. Then it's pretty trivial to do a key lookup as part of a test setup with logic to handle if the key value is pass or fail.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calling all JUNIT 4 Guru