How to write Unit Test in Java using JUnit4 in Eclipse and Netbeans

Writing Junit tests for Java classes in Eclipse and Netbeans IDE are super easy, and I will show you with that later in this JUnit tutorial. Before that, let’s revise what is unit test and why should you write them. Unit test is to test smaller unit of code, e.g. methods.  Writing unit test to test individual unit of code is one of the best development practice and helps to find bug earlier in development cycle. Though there are other unit testing framework available in Java e.g. TestNG, JUnit has it’s own place among Java developers. IMHO code review and unit testing are two most important practices for improving code quality and should always be followed during software development. Sad thing is that not every developer follows it; some programmer don’t write unit test due to ignorance and others due to laziness. Any way, it’s just start which take time, once you start writing unit tests, you will automatically start enjoying it. I have seen Java developers testing there code with main() method, but now they prefer to test them with JUnit testcases. I agree few initial tests are difficult because of knowledge and inertia and best way to approach is to start with simplest of JUnit tests. In this JUnit tutorial, I will show you how to write and execute JUnit test from Eclipse and Netbeans, two popular Java IDE. By the way, if you are looking for any good book on JUnit and unit testing, you should look Pragmatic Unit Testing in Java with JUnit, it's an amazing book and teaches a lot about both JUnit and unit testing in Java.
Read more »

0 Response to "How to write Unit Test in Java using JUnit4 in Eclipse and Netbeans"

Posting Komentar