After writing any code, every programmer will do some kind of testing to make sure the code works as expected. This testing is called 'unit testing'.
Unit testing is done in different ways. Some programmers write simple test applications to test their own code. Some others simply debug the code and change the values during debugging to make sure the code works fine for different cases.
Some facts about unit testing:
- Unit testing is done by developers.
- Quality department does different tests, they are not unit tests.
- Every programmer must do unit testing after finishing development or during development itself.
- Unit testing can be done by writing separate test applications to call your classes and methods to make sure the classes work as expected. This is called manual unit testing.
- Unit testing can be automated by writing unit test scripts. This is called Automated Unti Testing.
- In automated Unit Testing, after writing each class/method, you will write several Test methods to test the actual code. The test method will call your actual class/method with some sample inouts and compare the result with expected result. If the actual result from your code is same as the expected result, the Unit Test will record the result as "Success". Otherwise the test result will be recorded as "Fail". All of the unit test scripts can be executed together and you can get a summary of all results.
- Automated Unit test scripts can be saved and easily repeated so that everytime someone make a change in the project, hundreds of automated unit tests can be executed in few seconds to make sure that every piece of code is still working as expected.
- NUnit is one of the most popular automated unit testing tool for .NET applications.
- Automated unit tests can be done without using any unit testing tool like NUnit. However, unit test frameworks like NUnit make the job very easy.