Software testing is often thought of as simply making sure the application’s features work as expected.
If I do this then that should happen.
Sure, this is obviously a big part of what testing involves, but if that’s all we as testers did, we’d be failing our users. Proper test coverage involves both positive and negative testing.
If I do this then that shouldn’t happen.
The Difference Between Positive Testing and Negative Testing
Positive testing is the process of inputting valid data and making sure the application responds as expected. Exceptions (errors) are not expected in positive testing.
Negative testing is the process of inputting invalid data and making sure the application responds as expected. Exceptions (errors) are expected in negative testing.
The fact is, your users are going to input invalid data sometimes, and your software needs to be smart enough to handle those situations. For example, on a contact form, if ’email’ is required and the user inputs their first name in that field, what happens? Does your application clearly communicate that the user must input a valid email address?
This is negative testing.
Examples of Negative Tests
Negative testing can include all sorts of scenarios. Lets take a look at a few examples.
Assume we have a microblog web application we need to test. Here are some of the requirements of the app:
- The password must include both letters and numbers.
- The app allows you to publish 5 microblog posts per day.
- Only .jpg photos are supported in posts.
- No more than 200 words can be included in post.
Here are some negative test cases you would want to include in the test suite for this app:
- Create a password with only letters.
- Create a password with only numbers.
- Publish more than 5 posts in one day.
- Upload .png, .tif, and other non-jpg. file types.
- Write a post with more than 200 words.
These test cases will test how the web application handles invalid inputs. Does it throw proper errors? Does it crash? Does it not do anything at all?
Negative test cases make sure your software is doing more than it’s supposed to do by making sure it’s not doing what it isn’t supposed to do. Negative testing also improves the overall user experience of your product.
How to Write Negative Test Cases
Writing negative test cases requires some creative thinking. Negative testing is often called “destructive testing” as you’re essentially attempting to “break” the app. A good place to start is the requirements – don’t test the requirements directly though, test the opposite of them. Come at them from a different angle.
If you’re testing the requirements directly, you’re not conducting negative testing, you’re conducting positive testing.
Negative test cases should include tests outside of the specifications of the software. With negative testing, you’re testing unexpected inputs and scenarios, so it’s important to think outside of the box.
Negative testing helps ensure good test coverage and a better user experience. So you’ve tested all the requirements and your tests passed… that’s great! But the truth is you need to test more than that. Humans are not computers – they all operate differently, and we make mistakes. So make sure you’re including negative test cases in your testing projects.
At the end of the day, you’ll have a higher-quality product, happier users, and you’ll save time fixing things down the road.