Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calling all JUNIT 4 Guru

 
Z Sugiarto
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34396
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
C Popp
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic