Negative Testing in Software Testing

Negative testing is a software testing technique that involves providing invalid or unexpected input to a system to see how it reacts. This is done to identify potential bugs and vulnerabilities that may not be found through positive testing alone.

Positive testing focuses on verifying that a system works as expected under normal conditions. Negative testing, on the other hand, focuses on verifying that the system can handle unexpected or invalid input without crashing or producing unexpected results.

Negative testing is an important part of any software testing process, as it can help to improve the quality and reliability of the software. By identifying and fixing bugs and vulnerabilities early on, negative testing can help to prevent problems from occurring in the real world.

Types of Negative Testing

There are two main types of negative testing:

  • Functional negative testing: 
    This type of testing focuses on finding bugs in the functionality of the software.

    Example:
    • Trying to sign in to a website with an empty username or password field.
    • Trying to submit a form without filling in all of the required fields.
    • Trying to enter a negative number into a text field that only accepts positive numbers.
  • Non-functional negative testing: 
    This type of testing focuses on finding bugs in the non-functional aspects of the software, such as performance, security, and usability.

    Example:
    • Trying to access a website during peak traffic hours to see how well it performs under load.
    • Trying to log in to a website with a known weak password to see how secure it is.
    • Trying to use a website with a screen reader to see how accessible it is to users with disabilities.

Negative Testing Techniques

There are a number of different techniques that can be used for negative testing, including:

  • Boundary value analysis: 
    This involves testing the system with input values at the boundaries of its expected range.

    Example:
    Imagine you are testing a website that sells clothes. You would want to test the website with different values for the quantity field. For example, you would test the website with the values 0, 1, and 2. You would also want to test the website with invalid values, such as -1 and 1001.
  • Equivalence partitioning: 
    This involves dividing the possible input values into different equivalence classes and testing the system with one value from each class.

    Example:
    Imagine you are testing a website that allows users to search for products. You would want to divide the possible input values for the search field into different equivalence classes. For example, you would have one class for valid search terms and another class for invalid search terms. You would then test the website with one value from each class.
  • Error guessing: 
    This involves thinking about the different ways in which the system could fail and testing the system with input values that are likely to cause those failures.

    Example:
    Imagine you are testing a website that allows users to register for an account. You would want to think about the different ways in which the user could enter invalid information. For example, the user might enter an invalid email address or a password that is too short. You would then test the website with these invalid values.

Benefits of Negative Testing

Negative testing offers a number of benefits, including:

  • Improved software quality: 
    By finding and fixing bugs and vulnerabilities early on, negative testing can help to improve the quality and reliability of the software.
  • Reduced risk of failures: 
    Negative testing can help to identify potential problems before they occur in the real world, which can help to reduce the risk of failures and outages.
  • Increased user satisfaction: 
    By ensuring that the software can handle unexpected and invalid input, negative testing can help to improve the user experience and increase user satisfaction.

Example of Negative Testing Test Case

Test Case ID: TC-001

Test Case Description: Verify that the system rejects invalid login credentials.

Test Steps:

1. Enter an invalid username into the username field.
2. Enter an invalid password into the password field.
3. Click the "Login" button.

Expected Result:

The system should display an error message indicating that the login credentials are invalid.

Conclusion

Negative testing is an important part of any software testing process. By identifying and fixing bugs and vulnerabilities early on, negative testing can help to improve the quality and reliability of the software, reduce the risk of failures, and increase user satisfaction.