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

Having the most optimal product quality is the primary goal of the 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 consuming 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 craft or design the test scenarios to make sure the particular application or product performs the way it is supposed to.

How to write negative test cases

While it is definitely important to verify that the software performs its basic functions as intended, it is equally or more important to verify that the software is able to gracefully 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 several types 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 sections whereby we discuss what positive and negative testing is, how they’re different and we’ll describe some examples to understand what kind of negative tests can be performed while testing an application.

What is Positive testing and Negative testing?

Positive testing 

Positive testing, many times referred to as “Happy path testing” is generally the first form of testing that a tester would perform on an application. It is the process of running test scenarios that an end user would run for his use. Hence as implied, positive testing entails running a test scenario with only correct and valid data. If a test scenario doesn’t need data, then positive testing would require running the test 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 kind of positive testing. In alternate path testing, the test is again performed to meet its requirements but using the 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 result in both the cases is the same. 

Negative testing 

Negative testing commonly referred to as error path testing or failure testing 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, or handling a bad value more gracefully.

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:

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

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 verify 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

Let’s establish some ground rules here 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 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 the cases above, there are two basic parameters or techniques that formed a basis for designing sufficient amount of positive and negative test cases.

The two parameters are:

Boundary Value Analysis:

As the name itself implies, boundary indicates limits to something. Hence this involves designing test scenarios that only focus on the boundary values and validate how the application behaves. Therefore if the inputs are supplied within the boundary values then it is 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 is 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

Several 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 stand 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 about negative testing.




Recommended reading

41 comments ↓

#1 Kesav

Hi Sneha,

Good Article.. Every QA should do this negative testing in each and every module.

#2 Suresh

clear concept

#3 Inderdeep

Great Article!

Is their any way sure shot way to break a text field which accepts alphanumeric data?

#4 John

Good Article.

#5 Vinay Saxena

Nice article.
BVA and EQP are basic techniques.
Is/Are there any other techniques for negative testing.

#6 Mona

Nice one, supper………..

#7 Upneet Kailey

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…!

#8 Upneet Kailey

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.

#9 Lucas

Very Good Article! Thinks it can be considered as point of study to CTFL Foundation Level Certification.

#10 Nafisa Khattak

Great article, Thanks for sharing.

#11 Santhosh

Good one…

#12 Michael James

Nice! a very good read! I’ve learned something important today!

#13 Sneha

Many thanks to all of you for reading the article and finding value.

#14 Shabana Hasan

Excelent !!! defined v clearly

#15 CHETAN METKAR

@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…

#16 @halperinko - Kobi Halperin

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

#17 Ahmed Fathi Elgaly

Really so valued article, thank you

#18 PONSUKUMAR

There is an wrongly printed contents –> 1 – 250 is written as 1250

#19 AMPU DADA

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

#20 Gaurav

Nice Article…..

#21 Mohan

A small real-time example I faced:

___________
Requirement & implementation :

A =50

B= Anything >= 0 & <= A & non-decimal value & only numeric.

(Requirement document did not mention anything about negative values for B here because it is not at all given a thought !!!)

Logic: If B 10 Do ‘c’ and display 50-10 = 40. – (No harm)
B = 0 -> 0 Do ‘c’ and display 50-0 = 50. – (No harm)
B = 50 -> 50 Do ‘c’ and display 50-50 = 0. – (No harm)

b) B= 60 -> Display error message. – (No harm)
B = 25.5 -> Display error message. – (No harm)
B = XYZ -> Display error message. – (No harm)

c) B = -10 -> -10 Do ‘c’ and display 50-(-10)=60. – (Blunder leading to business loss)
___________________________________________________________

In the above example, assume: A = wallet amount, B = Recharge amount to be done, C = Recharge done, D = Remaining balance.

So if you don’t do negative testing, the recharge company may end up in loss because user is able to recharge without paying any amount.

#22 Mohan

*This below part missed from above comment after the sentence int he brackets.

Logic: If B 10 Do ‘c’ and display 50-10 = 40. – (No harm)

Continued…

#23 Pallavi

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?

#24 usha

Pallavi,

I would first ask him “you said temperature changes wrt, means at what intervals”.

#25 Jo

How do you best record neg and poss tests e.g. Separate scripts or as alternative or something else?

#26 prabhat

thanks to all,! I’ve learned something important today!

#27 Mohit

Hi,
If some one ask which methodlogy you used while testing , then what will we say.

#28 ganjar

“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 :D

#29 Balasubramanian S

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.

#30 MOHAN BABU

AWESOME

#31 G SATYENDER

FOR BEGINERS IT IS NICE TO LEARN ,AND MORE ABOUT THE SUBJECT.

#32 gh

Good

#33 Ritesh Sulakhe

Very good notes.

#34 Somanath Kumbhar

Thank you for such great article.

#35 Ayanda Ngwenze

Clear and well written . Thank you

#36 Ashish Tiwari

May i know what are the possible negative scenarios for an empty bottle?

#37 Asghar bhutto

Clear and well written. very usefull, Thanks!

#38 daniyal

Very Good and Informative Article.

#39 Lokesh

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 ..

#40 Cesar B

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?

#41 Richa

I would like to have negative Test Scenario for say an Application naukri.com

Leave a Comment