|
Answer» A standard unit test case comprises a known INPUT and an expected output. These two things need to be known before we run the test case. A known input is tested for a precondition and an expected output is tested by postcondition. Following are the best practices for writing unit test cases: - For every method, we need to have at least two unit test cases - a positive test case and a negative test case.
- If there are sub-requirements for a requirement, then those sub-requirements should have their own positive and negative test cases.
- Each test case should be independent of other test cases. If we make a CHAIN of unit test cases, then it would not be possible for FINDING the root cause of the test case failures.
- Mock all the external services that are used by the modules under test. This is necessary because we do not want to unnecessarily debug our modules under test due to the failures of the external systems.
- Configuration settings need not be tested as they won’t be part of any unit code. Even if we want to inspect the configuration, then test WHETHER the loading code is working or not.
- The unit test cases should be named consistently and clearly. The names of the test cases should be dependent on the OPERATIONS that the test case would test.
|