display | more...

A way of testing code, an integral part of the Extreme Programming methodology. Each unit of the program, usually a class in modern object-oriented programs, has a unit test written for it. The unit test utilizes the class it's testing in various ways, giving in certain inputs and verifying that the proper expected output occurs. Different than functional tests or acceptance tests which are larger scale tests, testing whole pieces of functionality.

I use JUnit for my Java tests.

One of the reasons the Extreme Programming methodology pushes Unit Testing is that it is a powerful tool for integration testing.

Extreme Programming champions the idea of continuous building and integrating of a system. Programmers are constantly adding, editing, and removing code from the system in parallel. Sounds dangerous, doesn't it? That is why integration testing is so important, hence the need for Unit Testing. Every atomic piece of code has its sister testing code, a Unit Test. This Unit Test is specifically tuned to check for the proper input and output for an atomic piece of code. With a collection of Unit Test, the entire system can be tested piece by piece. If a test fails, you know exactly what piece of code is not functioning properly. With this in mind, programmers can add, edit, and remove code to their hearts content. By checking the Unit Tests, they will know if their changes were successful, or if they broke part of the system.

This being said, Unit Testing is not a silver bullet for developing, but a part of an overall development strategy. Not implemented correctly, Unit Test can be harmful. Unit Test that are not kept up to date will display incorrect testing information, partial runs of Unit Test will produce unreliable data, or worse of all, Martin Fowler will mock you.

Log in or register to write something here or to contact authors.