Junit has become a major pocess of verifying your code before the actual testing done on the product you created.Junit can be related to a tester but its actually the developer who would code JUnit for the Java class created.
Why Junit?
A developer knows what he is coding for i.e the logic and the result he expects from the piece of code he writes.After having written that code and before integrating all the modules to appear as a application module , the developer can check his piece of module by writing junit. Thus junit is a unit testing of the modules done to verify the results are the same as expected.
Writing Junit
Junit for a module or class can be written after the class has been coded to verify that the results are expected Or
Junit for a class can be written before writing the actual class , meaning you define the class limits in junit and when ever u break those limits the junit fails, thus keeping the junit written in view we can write a stable class which would surely deliver what its written for.
How to Junit a class?
Junit is there with the eclipse IDE, to code a new junit for the class you written open File-> new junit test class and add the required info for your junit class.
Naming convention?
Example a class called "Simple" having "meth1" and "meth2" as methods needs to be junited, so first create a new junit class in eclipse as above to confirm the class is correct check it extends unitTestCase from junit framework.The test class is named TestSimple and the methods testMeth1 and testMeth2 as the method names for the test class .
so the class looks like
class TestSimple extends unitTestCase{
testMeth1(){
}
testMeth2(){
}
}
Saturday, 11 October 2008
Subscribe to:
Posts (Atom)