Lesson 35Introduction to Unit Testing with JUnit Framework
Software developers are not perfect, and bugs happen. Even if your program has no bugs, you may have used someone else’s code, which does have bugs. Moreover, code modification in one class or interface can break previously working code in another; this is called regression. Thorough testing is an important phase of any software development project.
Every developer knows how to test his or her code manually, and they do it. Periodically. But manual testing is a pretty boring routine. Would you want to start each day with manual testing to see if creating, updating, and deleting a sample purchase order still works? Neither do I. Testing should be automated.
The sooner your project team implements automated testing routines, the shorter the development cycle will be. The concept of test-driven development (TDD) suggests that testing should be embedded in the software development process from the very start of any new project.
There are different types of testing routines that have different goals. Here’s a description of the main types of testing (see more at the Wikipedia article Software Testing) :
- Unit testing is performed by a software developer and is targeted at small pieces of code. For example, if you invoke a method
calcTax()
with particular arguments, it should return the expected result. Java classes performing application-specific unit tests are written by software developers. Sometimes unit testing is ...
Get Java Programming 24-Hour Trainer, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.