What is Negative Testing and How to Write Negative Test Cases?

By Vijay

By Vijay

I'm Vijay, and I've been working on this blog for the past 20+ years! I’ve been in the IT industry for more than 20 years now. I completed my graduation in B.E. Computer Science from a reputed Pune university and then started my career in…

Learn about our editorial policies.
Updated February 25, 2024

In this post, we will discuss in detail what is negative testing and how to write negative test cases. Let’s get started.

Having the most optimal product quality is the primary goal of test organizations.

With the help of an efficient quality assurance process, test teams attempt to find maximum defects during their testing, thereby ensuring that the client or the end user of the product does not see any abnormalities with respect to its functioning in their own computing environment.

Since finding defects is one of the main goals of a tester, he/she needs to carefully design the test scenarios to make sure the particular application or product effectively performs the way it is supposed to.

How to Write Negative Test Cases

How to write negative test cases

While it is definitely important to verify that the software performs its basic functions as intended, it is also equally important to verify that the software is able to efficiently handle an abnormal situation.

It is obvious that most of the defects arise out of generating such situations with reasonable and acceptable creativity from the testers.

Most of us are already aware of the different kinds of testing such as functional testing, sanity testing, smoke testing, integration testing, regression testing, alpha and beta testing, accessibility testing, etc.

However, everyone will agree that whatever category of testing you perform, the entire testing effort can be basically generalized into two categories: positive testing paths and negative testing paths.

Let’s proceed with the next section whereby we discuss what positive and negative testing is and how they’re different. We will look into a few examples to understand what kind of negative tests can be performed while testing an application.

What is Positive and Negative Testing

Positive Testing 

Positive testing is often referred as “Happy path testing”. It is generally the first form of testing that a tester would perform on an application. This is the process of running test scenarios that an end user would run for his use. Hence, positive testing entails running a test scenario with only the correct and valid data.

If a test scenario doesn’t require data, then positive testing would require running the test in exactly the manner in which it’s supposed to run and hence to ensure that the application is meeting the specifications. 

Sometimes there may be more than one way of performing a particular function or task with an intent to give the end user more flexibility or for general product consistency. This is called alternate path testing which is also a type of positive testing.

In alternate path testing, the test is again performed to meet its requirements but using a different route than the obvious path. The test scenario would even consume the same kind of data to achieve the same result.

It can be diagrammatically understood from a very generic example described below: 

Negative and positive testing 1

A is a starting point and B is the endpoint. There are two ways to go from A to B. Route 1 is the generally taken route and Route 2 is an alternative route. Therefore in such a case, happy path testing would be traversing from point A to B using Route 1 and the alternative path testing would comprise taking Route 2 to go from A to B. Observe that the results in both the cases are the same. 

Negative Testing 

Negative testing is commonly referred to as error path testing or failure testing. This is generally done to ensure the stability of the application.

Negative testing is the process of applying as much creativity as possible and validating the application against invalid data. This means its intended purpose is to check if the errors are being shown to the user where it’s supposed to be, or handling a bad value more effectively.

It is absolutely essential to understand why negative testing is necessary.

The application or software’s functional reliability can be quantified only with effectively designed negative scenarios. Negative testing not only aims to bring out any potential flaws that could cause serious impact on the consumption of the product on the whole but can be instrumental in determining the conditions under which the application can crash. Finally, it ensures that there is sufficient error validation present in the software.

Example

If you need to write negative test cases about a pen. The basic motive of the pen is to be able to write on paper.

In this case, some examples of negative testing could be:

  • Change the medium that it is supposed to write on, from paper to cloth or a brick and see if it should still write.
  • Put the pen in the liquid and see if it writes again.
  • Replace the refill of the pen with an empty one and check that it should stop writing.

Practical Examples of Positive and Negative Testing

Let’s take an example of a UI wizard to create some policies. In the wizard, the user has to enter textual values in one pane and numerical values in another.

First pane

In the first one, the user is expected to give a name to the policy as shown below:

Negative and positive testing 2

Let’s also get some ground rules to make sure we design good positive and negative scenarios.

Requirements

  • The name text box is a mandatory parameter
  • The description is not mandatory.
  • The name box can have only a-z and A-Z characters. No numbers, special characters are allowed.
  • The name can be maximum 10 characters long.

Now let’s get to design the positive and negative testing cases for this example.

Positive test cases: Below are some positive testing scenarios for this particular pane. 

  1. ABCDEFGH (upper case validation within character limit)
  2. abcdefgh lower case validation within character limit)
  3. aabbccddmn (character limit validation)
  4. aDBcefz           (upper case combined with lower case validation within character limit)
  5. And so on

Negative test cases: Below are some negative testing scenarios for this particular pane.

  1. ABCDEFGHJKIOOOOOKIsns      (name exceeding 10 characters)
  2. abcd1234                  (name having numerical values)
  3. No name supplied
  4. sndddwwww_           ( the name containing special characters)
  5.  And so on.

Second pane

In the second pane, the user is expected to put in only numerical values as shown below:

Negative and positive testing 3

Here, let’s establish some ground rules as well:

Requirements

  • The ID has to be a number between 1- 250
  • The ID is mandatory.

Therefore here are some positive and negative test scenarios for this particular pane.

Positive test scenarios: Below are some positive testing scenarios for this particular pane.

  1. 12 (Entering a valid value between the range specified)
  2. 1,250 (Entering the boundary value of the range specified)

Negative test scenarios: Below are some negative testing scenarios for this particular pane.

  1. Ab               (Entering text instead of numbers)
  2. 0, 252        (Entering out of boundary values)
  3. Null input
  4. -2                 (Entering out of range values)
  5. +56             (Entering a valid value prefixed by a special character)

Basic Factors that Help in Writing Positive and Negative Tests 

If you closely observe the examples given above, you will notice that there can be multiple positive and negative scenarios. However, effective testing is when you optimize an endless list of positive and negative scenarios in such a way that you achieve sufficient testing.

Also, in both these cases, you will see a common pattern on how the scenarios are devised. In both cases, there are two basic parameters or techniques that form a basis for designing sufficient amounts of positive and negative test cases.

The two parameters are

Boundary Value Analysis

As the name itself implies, boundaries indicate limits to something. Hence this involves designing test scenarios that only focus on boundary values and validate how the application behaves. Therefore, if the inputs are supplied within the boundary values then they are considered to be positive testing and inputs beyond the boundary values is considered to be a part of negative testing.

For example, if a particular application accepts VLAN Ids ranging from 0 – 255. Hence here 0, 255 will form the boundary values. Any inputs going below 0 or above 255 will be considered invalid and hence will constitute negative testing.

Negative and positive testing 4

Equivalence Partitioning

In Equivalence partitioning, the test data are segregated into various partitions. These partitions are referred to as equivalence data classes. It is assumed that the various input data (data can be a condition) in each partition behave the same way.

Hence only one particular condition or situation needs to be tested from each partition as if one works then all the others in that partition are assumed to work. Similarly, if one condition in a partition doesn’t work, then none of the others will work.

Therefore it’s now very apparent that valid data classes (in the partitions) will comprise of positive testing whereas invalid data classes will comprise of negative testing.

In the same VLAN example above, the values can be divided into say two partitions.

So the two partitions here would be:

  • Values -255 to -1 in one partition
  • Values 0 to 255 in another partition
Negative and positive testing 5

 Conclusion

Many times, I have been faced with the situation where people believe that negative testing is more or less a duplication of the positive testing rather than believing the fact that it substantiates the positive testing.

My stance on these questions has always been consistent as a tester. Those who understand and strive for high standards and quality will doubtlessly enforce negative testing as a must in the quality process.

While positive testing ensures that the business use case is validated, negative testing ensures that the delivered software has no flaws that can be a deterrent in its usage by the customer.

Designing precise and powerful negative test scenarios requires creativity, foresight, skill and intelligence of the tester. Most of these skills can be acquired with experience, so hang in there and keep assessing your full potential time and again!

About the Author: This is a guest article by Sneha Nadig. She is working as a Test lead with over 7 years of experience in manual and automation testing projects.

Let us know your thoughts and experience with negative testing in the comments section below. We would love to hear from you.

PREV Tutorial | NEXT Tutorial

Was this helpful?

Thanks for your feedback!

Recommended Reading

45 thoughts on “What is Negative Testing and How to Write Negative Test Cases?”

  1. Well, can you please explain what could be scenarios for Date and Time combos. Like, I have to select Start Date, Start Time and End Date and End Time from 4 combos in order to perform a search function.

    How many negative scenarios can be there for this one? I have an idea but want to know from you, Sneha.

    Reply
  2. “Designing precise and powerful negative test scenarios requires creativity, foresight, skill and intelligence of the tester. Most of these skills can be acquired with experience, so hang in there and keep assessing your full potential time and again!”

    DAMN I LOVE THAT PART SO MUCH 😀

    Reply
  3. It seems the negative test case mostly limited in the scenarios which you can input invalid data. If the system is designed not allow freely input (e.g. using dropdown list or radio buttons in most input fields), or the requirement is mostly about the workflow and business logic, there is nothing input or the input is handle by system, it is very hard to design a negative test case, right?

    Reply
  4. I didn’t get the In depth difference between positive and negative testing . . .

    NV CHEPPINDHI ELA VUNDHI ANTE AKU IS PAK SO AK PAK KARAPAK ANI VUNDHI

    Reply
  5. Hi, In an interview the interviewer asked me to write only negative test cases for a grid with dynamic values in it like temperature which changes wrt time. And the grid has a ‘Export’ button to download table. What are the negative test cases i can write on it?

    Reply
  6. Is there any concept of Negative testing in QA. If a field should through error message when wrong data is provided, that is requirement. So how could you call it as a negative testing?

    Reply
  7. One question:
    Let’s say that your requirements specify what the application should do in case of receiving invalid data, i.e.:

    Req1. Field should accept values from 1 to 5
    Req2. If field receives any other value than specified on Req1, then error message should be displayed.

    So if I create a test case that inputs number 6 or a letter on such field (as told on Req2), should this test case be considered Positive or Negative?

    Reply
  8. Positive test cases: Below are some positive testing scenarios for this particular pane.

    1) ABCDEFGH (upper case validation within character limit)
    2) abcdefgh (lower case validation within character limit)
    3) aabbccddmn (character limit validation)
    aDBcefz (upper case combined with lower case
    4) validation within character limit)
    .. and so on.
    DOn’t you think in above positive scenarios 3rd on eis duplicate as it will cover in 1st 0r 2nd 0r 4th ..

    Reply
  9. Very nice article. Clear concept.

    I didn’t know that I’m doing Alternate Path Testing. That was new term for me.

    I studied BVA and ECP techniques but never understood with this much clarity. I will surely apply these techniques for test cases.

    Thanks for sharing…!

    Reply
  10. Thank you for your information.Sir i have doubt.Lets consider the login form.Here valid credential is positive test cases.Invalid credential is negative test cases.My doubt is how to write the if condition(Coding) when giving the invalid credential ie.negative testcases.

    Reply
  11. Thanks for an interesting article,
    I wouldn’t say Negative Testing comes to “ensure the stability of the application”, but rather to ensure a “Graceful Failure”.
    Which means to block and give proper failure to the user in case of unexpected / no allowed value or path is used, and especially Not to Crash 🙂 .
    Note that these are still (at most cases) covering Requirements – just their over the edge values.
    While we tend to think in boundary values – there are many more procedural/interrupt scenarios to think of – such as Loss of Mobile network data connection during transactions and more.
    The drawing of Valid and Invalid values above – can be improved, to include over the edge positive cases (small up to very large), as well as common failure scenarios – such as around Half Integer value in case that Signed/Unsigned Integer was not properly handled.
    Another thing many testers miss – is the consideration of the boundaries of an Output value/s and not only the Input values,
    like – What may cause result to be a division by 0.

    @halperinko – Kobi Halperin

    Reply
  12. @sneha mem
    good article and clearly the fundamental of how to write a negative test cases.
    but i have a doubt about negative test data.how to decide negative test data against real scenario???
    give some example to elaborate this…

    Reply

Leave a Comment