Positive vs Negative Testing: Differences, 24 Real Test Cases and a Checklist
Positive testing checks that software works with valid input. Negative testing checks that it fails safely with invalid input, such as wrong types, empty fields and out-of-range values. See both applied to a real signup form, with 24 test cases we ran and the bug only a negative test caught.
- Positive vs negative testing: positive tests prove the happy path works; negative tests prove bad input is rejected safely.
- Our signup form needed 6 positive tests and 18 negative ones; invalid inputs usually outnumber valid ones.
- When we removed the maximum-age check, all 6 positive tests still passed. Only the negative test for age 121 failed.
- A good negative test checks the specific error, not just “something failed”.
Most bugs that reach production are not in the happy path. Someone types a space into a username, pastes an email with no domain, or an API sends the number as text. Software that only works with perfect input fails in exactly those moments. Positive vs negative testing is the simplest way to think about covering both. To make it concrete, we wrote a small signup validator, designed 24 test cases, and ran them with pytest 9.2.0 on Python 3.13.
Quick answer
Positive testing uses valid input and checks that the system does what it should: the account is created, the payment succeeds, the report downloads. Negative testing uses invalid or unexpected input and checks that the system refuses it gracefully: a clear error, no crash, no corrupted data and no security hole. You need both; a requirement is only covered when its happy path and its failure paths are tested.
What is positive testing?
Positive testing, sometimes called happy-path testing, confirms that a feature works when used as intended. It answers “does it do what it promises?”. Examples: logging in with a correct password, searching for a product that exists, uploading a supported file type within the size limit. Positive tests come first, because if the main flow fails, nothing else matters.
What is negative testing?
Negative testing, sometimes called error-path testing, feeds the system input it should reject and checks the response. It answers “what happens when things go wrong?”. Examples: a wrong password, an empty required field, a 50 MB file when the limit is 10 MB, letters in a phone number, an expired session. A negative test passes when the system rejects the input correctly. It fails when the bad input is accepted, crashes the app or produces a confusing error.
A real example: the signup validator
Our requirements for a signup form:
- Username: 3 to 20 characters, letters, digits and underscores only.
- Age: a whole number from 18 to 120.
- Email: something@domain.tld, no spaces.
- Password: at least 8 characters, not letters only.
import re
def validate_signup(username, age, email, password):
errors = []
if not isinstance(username, str) or not re.fullmatch(r"[A-Za-z0-9_]{3,20}", username or ""):
errors.append("username")
if not isinstance(age, int) or not 18 <= age <= 120:
errors.append("age")
if not isinstance(email, str) or not re.fullmatch(r"[^@\s]+@[^@\s]+\.[^@\s]+", email):
errors.append("email")
if not isinstance(password, str) or len(password) < 8 or password.isalpha():
errors.append("password")
return errors
The function returns a list of fields that failed. An empty list means the signup is valid. Returning field names, rather than true or false, lets each negative test check that the right field was rejected.
The 24 test cases
| Field | Positive (must be accepted) | Negative (must be rejected) |
|---|---|---|
| Username | “abc” (min), 20 letters (max) | “ab”, 21 letters, “bad name”, empty, None |
| Age | 18 (min), 120 (max) | 17, 121, -1, “30” as text, True, 30.5 |
| “a@b.co” | “no-at-sign”, “a@b”, “a b@c.com”, empty | |
| Password | “abcdefg1” | “short1”, “onlyletters”, None |
That is 6 positive cases and 18 negative ones. The ratio is typical: there are usually a few ways to be right and many ways to be wrong. Notice that the positive cases sit exactly on the boundaries (3 and 20 characters, ages 18 and 120), and so do many negative ones (2, 21, 17, 121). Boundaries are where off-by-one bugs live; see our boundary value analysis guide.
The tests in pytest
import pytest
from signup import validate_signup
OK = dict(username="demo_user", age=30, email="demo@example.com", password="s3cretpass")
@pytest.mark.parametrize("field, value", [
("username", "abc"), ("username", "a" * 20), ("age", 18), ("age", 120),
("email", "a@b.co"), ("password", "abcdefg1"),
])
def test_positive(field, value):
assert validate_signup(**{**OK, field: value}) == []
@pytest.mark.parametrize("field, value", [
("username", "ab"), ("username", "a" * 21), ("username", "bad name"),
("username", ""), ("username", None),
("age", 17), ("age", 121), ("age", -1), ("age", "30"), ("age", True), ("age", 30.5),
("email", "no-at-sign"), ("email", "a@b"), ("email", "a b@c.com"), ("email", ""),
("password", "short1"), ("password", "onlyletters"), ("password", None),
])
def test_negative(field, value):
assert validate_signup(**{**OK, field: value}) == [field]
........................ [100%]
24 passed in 0.10s
Each test starts from one known-good signup and changes exactly one field. That isolates the cause: if a negative test fails, you know which rule is broken. The == [field] assertion also confirms that no other field was wrongly rejected. Parametrize keeps 24 cases in two short functions; our pytest parametrize guide shows more patterns.
The bug only a negative test caught
To see the value of negative tests, we simulated a common developer mistake: checking only the minimum age. We changed one line to if not isinstance(age, int) or age < 18: and ran the suite again:
FAILED test_signup.py::test_negative[age-121] - AssertionError: assert [] == ['age']
1 failed, 23 passed in 0.19s
All six positive tests still passed, because the happy path still worked. An age of 121 was silently accepted, and only the negative boundary test noticed. Without it, the bug would have shipped. That is the core argument for negative testing: positive tests tell you the feature works, negative tests tell you its rules hold.
Tip: a quick way to judge a test suite is to break one validation rule and see whether any test fails. If nothing fails, you are missing a negative test.
Positive vs negative testing compared
| Aspect | Positive testing | Negative testing |
|---|---|---|
| Input | Valid, expected | Invalid, unexpected or malicious |
| Question answered | Does it work? | Does it fail safely? |
| Passes when | The action succeeds | The input is rejected with the right error |
| Typical number of cases | Fewer | More |
| Finds | Broken core features | Missing validation, crashes, security gaps |
| Priority | Run first | Run right after, before release |
| Example | Login with correct password | Login with wrong password, empty password, SQL in the username |
How to find negative test cases
- Equivalence partitioning: split inputs into valid and invalid groups and test one value from each invalid group. See our equivalence partitioning guide.
- Boundary values: test just outside each limit, such as 17 and 121.
- Wrong types: text where a number belongs, a boolean, a decimal, null. Our test with
"30"as text matters for APIs, where JSON numbers often arrive as strings. - Empty and missing: empty strings, whitespace only, missing fields.
- Format breakers: spaces, emoji, very long input, special characters such as quotes and angle brackets.
- State and sequence: submitting twice, using an expired link, acting after logout.
Generating varied input automatically helps too; our test data generation guide covers Faker and edge cases.
What a good negative test checks
“It did not crash” is not enough. A strong negative test checks that:
- The input is rejected, not silently accepted or “fixed”.
- The right rule triggered, with a clear message the user can act on.
- Nothing was saved or changed: no half-created account, no charge.
- The response is correct for an API, usually 400 or 422 rather than 500. Our HTTP status codes cheat sheet lists them.
- No sensitive details leak, such as stack traces or whether an email is registered.
Getting the balance right
Negative inputs are endless, so you cannot test them all. Prioritise by risk: validation that protects money, security and data integrity deserves the most negative cases, while a cosmetic field needs only a couple. A practical rule from many teams is at least one positive and one negative test per requirement, then more where failure is costly. Automate the stable ones at the unit or API level, where they run in milliseconds, and keep a few end-to-end checks for critical forms. Our risk-based testing guide shows how to rank features.
Positive and negative testing checklist
- Every input has at least one positive and one negative case.
- Both sides of every boundary are tested.
- Wrong types, empty values and missing fields are covered.
- Each negative test checks the specific error, not just failure.
- Rejected requests change no data.
- Error messages are clear and leak nothing sensitive.
- API errors return 4xx codes, never 500.
- New bugs found in production get a new negative test.
Final thoughts
Positive vs negative testing is not a choice between two techniques; it is two halves of the same job. Positive tests prove the feature works for the people using it correctly. Negative tests prove its rules survive everyone else. Our 24-case example showed the payoff in one line: when a validation rule broke, every positive test stayed green and only a negative test caught it. To write these cases in a consistent format, see our how to write test cases guide.
Frequently asked questions
What is the difference between positive and negative testing?
Positive testing uses valid input and checks that the feature works. Negative testing uses invalid or unexpected input and checks that the system rejects it safely with a clear error.
What is an example of a negative test case?
Entering an age of 121 when the allowed range is 18 to 120, and checking that the form rejects it with an age error and saves nothing.
Which should be done first, positive or negative testing?
Usually positive testing, because there is little point testing error handling if the main flow is broken. Negative testing should follow before release.
How many negative test cases do I need?
At least one per input rule, plus both sides of each boundary. Add more for high-risk areas such as payments, security and data integrity.
When does a negative test pass?
It passes when the system rejects the invalid input correctly: the right error, no crash, no saved data and no leaked details.
Keep learning
Need help with testing, WordPress or SEO?
We help teams ship better software and grow their sites. Tell us what you are working on and we will suggest a clear next step.