I am kind of new to writing JUNITtest cases.Though I have tried to write 2 or 3 junit classes, I think I do not know the basic concept of writing JUnit.Please tell me what should I start with.Also I am using NetBeans as my IDE.If you can also tell how NetBeans support Junit that will be great.
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
It might be a good idea for you to tell us more detail about the sort of code you wish to test. If you can show us the methods of a class or the API that you want to test, we can probably talk you through the thought processes when setting up a JUnit test.
It's quite likely, though, that your existing code was not designed to be very testable. JUnit is still useful, but you may find that you need to use some "tricks of the trade" to test things.
Testing existing code isn't easy, because most often it isn't written with testability in mind. You could write whole books about the topic.
Fortunately, Micheal Feathers already did us the favor: "Working Effectively With Legacy Code" is what you want to read. It might be a little bit of a tough read if you are new to JUnit, though...
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
I'd recommend you skill up on refactoring before you delve too much into writing the junit tests for legacy code. The reason is that refactoring the code will save you from having to write a lot of supporting test code. For example, you won't have as many anonymous inner classes.
For me, the basic procedure would be something like: 1) Examine the code and notice a test case 2) Is the test case easy to write? If so, write it, goto 1. Else 3. 3) refactor out a chunk of code in the vacinity of what you want to test. Goto 2.
Repeat the above until you're exhausted. [ October 26, 2006: Message edited by: Tony Smith ]
In the renaissance, how big were the dinosaurs? Did you have tiny ads?
Free, earth friendly heat - from the CodeRanch trailboss