What is Negative Testing(Test cases with Example)?

Negative Testing

Negative testing is a kind of software testing that examines the software program for unforeseen input data and situations. Unusual data or situations might range from incorrect data types to a powerful cybersecurity breach. The goal of negative testing is to keep software applications from malfunctioning as a result of negative inputs and to enhance quality and stability.

We can only ensure that our technology works in regular situations by doing positive testing. To create an error-free system, we must guarantee that our system can manage unforeseen situations.

You will learn the following in this tutorial −

  • What is Negative Testing?

  • Example of Negative Testing

  • Why do Negative Testing?

  • How to do Negative Testing

  • Advantages of Negative Testing

  • Disadvantages of Negative Testing

Example of Negative Testing

Think about the situation of an elevator, which is a well-known example of negative testing.

We are all familiar with the operation of an elevator. These will be defined as lift requirements, such as pushing the floor number button to allow the lift to move to that specific floor.

When the elevator reaches the target floor, the door opens, and so on.

Let's take a look at some of the worst-case possibilities for the elevator. Some of them include −

Negative TestingPositive Testing
What follows if the number of individuals (weight) surpasses the maximum allowed?Makes the assumption that only the stated number of people will use the elevator.
What if someone smokes or starts a fire inside the elevator?Inside the elevator, there would be no smoke or fire.
What happens if the electricity goes off while the machine is running?There will be no power outage while the elevator is in operation.

All of these situations will be subjected to negative testing. The significance of all this is that we cannot guarantee that all of these will not occur, therefore we must keep them restricted.

Check out the following scenario: the weight situation is examined, and the elevator operates abnormally if there is an overweight situation. This may have an effect on the system's dependability and may potentially endanger people's lives. This describes what negative testing is and why it is important.

The same logic is used in the software. We diverged from the standard operating procedure for negative testing. Let's look at few examples.

Take, for example, a registration form.

Negative TestingPositive Testing
Insert an incorrect email address in the email field.In the email box, only genuine email addresses will be inserted.
In a contact number box, try entering a fake phone number (characters).In the number field, only numbers will be inserted.
Add an image with a size that exceeds the given limit.Only photos with a size less than the set limit will be uploaded.
In the picture upload section, upload incorrect files such as XML, SQL, and so on.Submit only valid picture formats such as jpg, png, and so on.

As previously said, we must ensure that our system will function successfully under all of these undesirable scenarios. Consider the following scenario: someone enters a character in the number field, the system is unable to interpret the unusual input since it is anticipating a number and the system failures. So if someone attempts a SQL injection and deletes all of our data from the database? Such prospective damages are too great for us to endure. As a result, negative testing is critical.

Why Negative Testing?

Because testing costs time and resources, determining 'what,' 'how,' and 'how much’ to check is critical. We must make an informed decision about whether or not to conduct negative testing in our system. So, let's take a closer look at why negative testing is so important.

Organization perspective

It is the business’s job to give a high-quality product to its customers. Negative testing is required to accomplish this.

Negative testing is required as part of the confirmation process in the case of failure.

We may not be able to construct a completely error-free technology, but we must ensure that we have taken all possible steps to avoid a breakdown, and in order to do so, we must do negative testing.

One element that we must examine is the effect. Suppose that we have performed positive testing on an e-commerce website to ensure that everything is in order. But what if there is indeed a flaw in our system which allows someone to perform SQL injection and wipe out all of our information? That would be a significant security violation. Negative testing is also intended to stop these types of situations.

For applications that are available to the general public, mostly websites, we must constantly take into consideration that we do not have much control over the application's usage method, thus we must do negative testing to ensure that all such scenarios are covered and controlled.

Another point to remember is that there are several dark hackers around nowadays searching for a chance to disrupt the system. Negative testing covers a crucial situation called hacking.

Client perspective

Customers typically want zero-risk goods, thus negative testing is required. If the product is critical, such as e-commerce or online stock, safety and negative testing are required.

The company's main concern with negative tests is the expense. However, after the effects have been assessed, it is up to the customer to determine whether or not to conduct negative testing.

How to do negative testing?

To conduct negative testing, we must evaluate all conceivable scenarios. That is, if it is conceivable, we must include it in the Test Case, even though it is not the correct method to utilize it. For instance, when we see an email box, consider all potential entries except the actual email format. Similarly, if we see a picture upload box, we must verify it with every available file.

We must prioritize the inputs while building negative test cases; else, there will be a large number of examples. For instance, in an image field in which only '.png' files are allowed, we can have a variety of uploading alternatives such as 'jpeg,' 'XML,' 'Xls,' and so on. As a result, we must prioritize the alternatives. For example, XML and SQL can have a higher influence than jpeg and xls, thus we should target SQL and XML scenarios initially. In this situation, we must prioritize the instances before executing them in order to save time and money on testing.

The Benefits and Drawbacks of Negative Testing −

Negative testing, just like all the other testing methodologies, has advantages and disadvantages that are mostly determined by the 'where,' 'when,' and 'how' to utilize them. Let's take a closer look at this.

Advantages of Negative Testing

  • Since we all understand, negative testing is critical to ensuring the quality of the product. To guarantee that negative testing is extremely important, a good quality product is a zero-risk product.

  • Negative testing ensures that all conceivable scenarios are addressed. Negative test cases might emerge either purposefully or inadvertently. So, in order to ensure that all instances are addressed, we must do both positive and negative testing.

  • Negative testing will give the customers increased certainty before going live.

Disadvantages of Negative Testing

  • In certain circumstances, negative testing in software engineering is a waste of money and effort. Intense negative testing is unnecessary in several circumstances. For example, if an application is designed for an individual user, we don't have to explore the implications of 100 users using the system at the same time. As a result, selecting criteria in negative test scenarios is critical. There'll be situations when we do not need to conduct negative testing on a certain system.

  • Negative test cases must be created by educated and professional individuals.

  • Negative testing, according to the customer, is yet another source of unneeded launch delays and expenses.

  • There is a possibility that a group may devote more work and attention to negative testing. There is a possibility that testers may devote a significant amount of time and resources to negative testing, resulting in a decreased focus on positive testing.

Updated on: 09-Jun-2021

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started