150 likes | 330 Views
J-UNIT TESTING IN ECLIPSE. Mahesh Raju Deshpande. BENIFITS OF UNIT TESTING. 1. Facilitates change : Unit testing allows the programmer to refactor code at a later date, and make sure the module still works correctly.
E N D
J-UNIT TESTING IN ECLIPSE Mahesh Raju Deshpande
BENIFITS OF UNIT TESTING 1.Facilitates change: Unit testing allows the programmer to refactor code at a later date, and make sure the module still works correctly. 2.Simplifies integration: By testing the parts of a program first and then testing the sum of its parts, integration testing becomes much easier. 3.Documentation: Unit testing provides a sort of living documentation of the system. Developers looking to learn what functionality is provided by a unit and how to use it can look at the unit tests to gain a basic understanding of the unit's API.
INTRODUCTION TO JUNIT JUnit is an open source Java testing framework used to write and run repeatable tests. It is an instance of the xUnit architecture for unit testing frameworks. Developed by Erich Gamma and Kent Beck. Key element of Test-driven Development. JUnit test generators now part of many Java IDEs (Eclipse, BlueJ, Jbuilder, DrJava).
LET'S GET STARTED WITH THE ACTUAL PROCEDURE (1).Firstly create a code to be tested. (2).Separate the unit test code from application code. Select the project-->File-->New-->Source Folder-->give it a name(I have named it “test”)-->Finish.
(3). Put test classes into same package as the code being tested. Select src folder of test classes-->File-->New package-->enter the package name-->Finish.
(4). Now create a JUnit test. Select the newly created package-->File-->New-->JUnit Test Case then enter the Name of the Test and the Class under test-->Next
There are two versions of JUnit as can be seen in prev slide, JUnit 3 and Junit4. If we choose JUnit 3, we have to add a prefix “test” to a method name. In JUnit 3. you could choose from several runners: text, AWT, or Swing. JUnit 4 only uses text runners. JUnit is an external library and hence we have to add the JUnit library to the build path. JUnit 3 and JUnit 4
(5).We have to modify the test cases to actually test the class to be tested.
(6). Once the test methods are modified, we can run them. Run-->Run As-->JUnit test. Then Select the Eclipse JUnit launcher-->OK.