Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is JUnit Cumbersome

 
Anil Vupputuri
Ranch Hand
Posts: 527
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's hardly cumbersome, in my opinion.
See this quickstart tutorial for using the JUnit wizards of Eclipse.
 
J. B. Rainsberger
author
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by "automate test cases"?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34195
340
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Anil Vupputuri
Ranch Hand
Posts: 527
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 34195
340
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic