Positive & negative testing
Introduction
There are two main testing strategies in software testing: positive testing and negative testing.
The core difference between positive testing and negative testing is that throwing an exception is not an unexpected event in the latter. When you perform negative testing, exceptions are expected – they indicate that the application handles improper user behaviour correctly.
It is generally considered a good practice to combine both the positive and the negative testing approaches. This strategy provides higher tested application coverage as compared to using only one of the specified.
Positive testing
Determines that your application works as expected. If an error is encountered during positive testing, the test fails.
Negative testing
Ensures that your application can gracefully handle invalid input or unexpected user behaviour. For example, if a user tries to type a letter in a numeric field, the correct behaviour in this case would be to display the “Incorrect data type, please enter a number” message. The purpose of negative testing is to detect such situations and prevent applications from crashing. Also, negative testing helps you improve the quality of your application and find its weak points.