12

What are positive test cases and negative test cases?

Upon Googling about it I have found answers that are very confusing. Can anyone explain with example?

Daniel Widdis
  • 8,424
  • 13
  • 41
  • 63
a Learner
  • 4,944
  • 10
  • 53
  • 89

6 Answers6

27

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.

Scott Helme
  • 4,786
  • 2
  • 23
  • 35
  • 1
    IS it right to say that in positive test case we use only valid input and with negative test case we use invalid input? – a Learner Oct 14 '13 at 08:03
  • Yes it is. Example, a numeric input field expecting 1-10. Positive test case is numbers 1-10 and negative would be 0 and below or 11 and above. – Scott Helme Oct 14 '13 at 08:16
  • Did that answer your question? – Scott Helme Oct 14 '13 at 09:28
  • What about the methods that do nothing when input irrelevant? Like for example in OnHit(Animal) method I increment bearHits when object is a bear and do nothing when it's a rabbit or something else, yet it's part for normal behavior. So when OnHit() gets a rabbit as parameter would that be a negative test case? – Rytis I Apr 08 '14 at 13:49
  • 1
    @aLearner I think your comment highlights what's the real difference: invalid vs valid input data. If the purpose of negative/positive is to determine if the system behaves _as expected_ then I don't think the difference is not that relevant except probably as way of prioritizing testing effort. – pgpb.padilla Dec 19 '14 at 04:37
  • If you are lucky, you mostly work on user stories with defined *acceptance criteria*. When AC is provided it is a huge aid in writing test cases. In fact AC entries come in three flavors: *Positive test*, *Negative test*, and [*Gold plating*](https://en.wikipedia.org/wiki/Gold_plating_(software_engineering)). This last category is what you do not need to implement at all. I frequently find myself gold plating if not instructed not to! – Majid Fouladpour Jul 06 '16 at 22:36
1

Positive case is a case where the system validated against the valid input data

For example, consider a scenario where you want to test a application which contains a search field and requirements say that you should not enter special characters.

ID: 1

Name/Idea: Verifying that search field works with valid input

Precondition steps: "Search" screen should be opened

Steps to reproduce:

  1. Fill search field with valid information

  2. Tap on "Search" button

Expected result: The screen with results of search should be displayed

Positive/Negative: 1

Negative case is case where the system validated against the invalid input data. A negative test checks if a application behaves as expected with its negative inputs

For example, consider the same example which should accept only letters. So here provide the characters like “@,#,/” in the search field and check the behavior of application, either it should show a validation error message for all invalid inputs or system should not allow to enter special characters.

ID: 1

Name/Idea: Verifying that search field works with invalid input

Precondition steps: "Search" screen should be opened

Steps to reproduce:

  1. Fill search field with invalid information (e.g. @,#,/)

  2. Tap on "Search" button

Expected result: Pop-up with error message should appear

Positive/Negative: 0

QArea
  • 4,955
  • 1
  • 12
  • 22
1

I dont know but I was somewhat dissatisfied with above answers. So here are my views upon this topic:

  1. Positive testing is the testing for something that should happen, does happen.
  2. Negative testing is the testing for something that should not happen, does not happen.

Lets have a scenario where we have two requirements: Requirements:

  1. A text box to enter some characters.
  2. A button to submit entered text to the server.
  3. A message to be displayed when number of characters is less than 5. "Less than 5 characters".
  4. A message to be displayed when server accepts text submitted. "Text accepted".

Now, a positive scenario would be:

  1. Enter "abcdef" in the text box.
  2. Click on submit button.
  3. "Text Accepted" must be displayed.

On the other hand, a negative scenario would be:

  1. Enter "abcd" in the text box.
  2. Click on submit button.
  3. "Text Accepted" must not be displayed.
0

A positive test case is when the test is designed to return what is expected according to the requirement.

A negative test case is when the test is designed to determine the response of the product outside of what is defined.

You don't determine the type of test by the results, but by the expected result based on the input.

Hope it makes sense, here's a good example http://osdir.com/ml/programming.software-qa/2004-12/msg00060.html

femi igun
  • 3
  • 1
  • 4
0

positive or negative is meaningless unless you put the requirement in the content. Let's say, one requirement is "the log in should fail if the user ID is not correct". I know it's bit counter-intuitive, a positive test is the type of test that will generate a failure in logging in, while the negative test will generate the result of successful log in.

waterinusa
  • 71
  • 1
  • 4
-1

Positive test cases we are using for checking some scenario like whatever scenario we are using for our code.

Negative test cases we are checking some specific scenario in negative way.

By the help of both we can increase code coverage.

Ankit
  • 593
  • 4
  • 12