File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Testing and the fly likes Is JUnit Cumbersome Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Is JUnit Cumbersome" Watch "Is JUnit Cumbersome" New topic
Author

Is JUnit Cumbersome

Anil Vupputuri
Ranch Hand

Joined: Oct 31, 2000
Posts: 527
I really haven't used it but thats what I observed when I went through the sample application. How flexible is this to integrate with Eclipse and automate test cases.
Thanks.


SCJP 1.5, SCEA, ICED (287,484,486)
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
It's hardly cumbersome, in my opinion.
See this quickstart tutorial for using the JUnit wizards of Eclipse.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
J. B. Rainsberger
author
Ranch Hand

Joined: Aug 05, 2004
Posts: 87
What do you mean by "automate test cases"?


Author of <a href="http://www.amazon.com/exec/obidos/ASIN/1932394230/ref=jranch-20" target="_blank" rel="nofollow">JUnit Recipes: Practical Methods for Programmer Testing</a>
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Its a lot less cumbersom than trying to fix defects caused by ununit-tested code.

We 'automate' our unit tests as part of our Ant build, which is a fairly common approach. A complete build will also run every TestCase found in the app. Once the app gets to production, a failed TestCase will also fail the build. Quite easy to do and the JUnitReport task generates a pretty comprehensive overview of the results. All this can be run using Eclipse's Ant integration.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30293
    
150

Anil,
Sometimes it seems more cumbersome than it is in tutorials because they have to explain every little thing. After you've written a couple test cases, it just becomes part of your thought process.


[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
Anil Vupputuri
Ranch Hand

Joined: Oct 31, 2000
Posts: 527
Originally posted by Paul Sturrock:
Its a lot less cumbersom than trying to fix defects caused by ununit-tested code.

We 'automate' our unit tests as part of our Ant build, which is a fairly common approach. A complete build will also run every TestCase found in the app. Once the app gets to production, a failed TestCase will also fail the build. Quite easy to do and the JUnitReport task generates a pretty comprehensive overview of the results. All this can be run using Eclipse's Ant integration.


Thanks for your answer.

However my interpretation of 'automate' test case is,

Can JUnit enable you to quickly produce all the required test cases for thorough construction testing, which is impractical to achieve manually. Such as creating test cases that execute every possible branch of each method it tests.
For example, if the method contains a conditional statement (such as an if block), can JUnit generate test cases that test the 'true' and 'false' outcomes of the 'if' statement.

Thanks.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30293
    
150

Anil,
Junit doesn't generate tests. It is a framework for writing tests. If you can write a conditional in the code, you can certainly write two tests for it.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


can JUnit generate test cases that test the 'true' and 'false' outcomes of the 'if' statement.

No. I think you are missunderstanding what you use Unit Test for. You don't write them to check that every line of code does exactly what you expect it too. You write them with the a "black box" idea in mind. If you have conditionals you must expect your method to behave in different ways for different inputs - so you write a TestCase which includes an example of these different inputs.

You can't automate testing in this way. Testing like this is not a dumb process, but requires the tester to pick appropriate inputs to test their method, and to anticipate somewhat what could go wrong.

Trust me. The time spent hand crafting good, repeatable unit tests is time very well spent. Unfortunately, you really have to have worked on a project where this didn't happen to get a good understanding why this is such a good idea.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Originally posted by Anil Vupputuri:
For example, if the method contains a conditional statement (such as an if block), can JUnit generate test cases that test the 'true' and 'false' outcomes of the 'if' statement.

As others already pointed out, JUnit isn't meant for this type of testing. If you're looking for a mutation testing framework, you should look into JTest (a commercial product). Here's an article that seems to describe how to combine JUnit and JTest:
JUnit + Jtest = Automated Test Case Design and Static Analysis
J. B. Rainsberger
author
Ranch Hand

Joined: Aug 05, 2004
Posts: 87
If you are looking for software to generate tests, the best candidate I have heard of is from Agitar. Their concept, "software agitation" consists essentially of observing the software under test, identifying invariants, then making it push-button easy to promote those observations to JUnit-based assertions.

It is important to understand that JUnit is a way to write tests. JUnit does not test software--you test software, possibly by writing your tests with JUnit. No piece of software can know what you intended to write, so no piece of software can tell you what your assertions should be.

For that, you still have to think.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is JUnit Cumbersome