Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is positive test and negative test in unit testing

Tags:

I'm pretty new to TDD. I see some docs says about positive test, negative test, boundary test etc. Can any one tell me the difference between a positive test and negative test? Is there any reference out there that says about the different types of tests? (I'm not looking for books)

like image 644
VJAI Avatar asked Nov 17 '11 05:11

VJAI


People also ask

What is negative unit testing?

Negative unit tests are useful for more than just making sure that every line of code is tested. Indeed, they're sometimes more important than positive tests. Negative tests demonstrate that your code properly handles invalid data, unexpected user input, and changes in other parts of the code base.

What is a positive unit test?

Positive unit tests are tests that return expected results when you present valid data to the tested code. Think of the classic calculator. A positive test for an addition method might execute with data points 2 and 3 while asserting the output is 5. This is a simplistic example, of course, but the idea is the same.

What is positive and negative test cases example?

A positive test case tests that a system does what it is supposed to. Example: will allow you to login when valid credentials are supplied. A negative test case tests that a system does not do things it shouldn't. Example: should not allow you to login when invalid credentials are supplied.

Which technique is used for positive and negative testing?

Testing Technique used for Positive and Negative Testing:Boundary Value Analysis.


2 Answers

Positive Testing - testing the system by providing valid data.

Negative Testing - testing the system by providing invalid data.

For Example, an application contains a textbox and as per the user's Requirements the textbox should accept only Strings.By providing only String as input data to the textbox & to check whether its working properly or not means it is Positive Testing. If giving the input other than String means it is negative Testing..

Negative testing improves the testing coverage of your application. Using the negative and positive testing approaches together allows you to test your applications with any possible input data (both valid and invalid) and can help you make your application more stable and reliable.

Refer this Glossary for different type of tests

like image 106
Rohan Patil Avatar answered May 04 '23 01:05

Rohan Patil


In terms of unit testing, (which is the focus of TDD) the concept can be described simply as follows:

  • A positive test checks if a function/method behaves as expected with its expected input.
  • A negative test checks if a function/method behaves as expected with bad input. (you should have enough negative tests to cover all possible definitions of "bad", ideally") See this question for more information.
like image 42
mpontillo Avatar answered May 03 '23 23:05

mpontillo