Test Case
- In Turkish
- test senaryosu
In short
A test case is a check of one specific behavior: starting conditions, input or steps, and the expected result that shows if the software behaves correctly.
What is a test case?
A good test case is precise enough that anyone, or any machine, can run it and agree on the outcome. For a login form it might read: given a registered user, when they enter the correct email and a wrong password, then an error message appears and they stay logged out. Manual test cases are often written in a test management tool with an ID, preconditions, steps and expected results.
In automated tests, each test function is a test case, and related ones are grouped into a test suite. The Arrange, Act, Assert pattern keeps them readable: set up the data, perform one action, then check the result. Each case should test one thing and have a name that explains it, such as rejects_expired_coupon, so a failure tells you immediately what broke.
Choosing cases well matters more than writing many. Cover the normal path, invalid input, empty and very large values, and the boundaries where behavior changes, such as exactly 18 years old for an age check. Bugs cluster at those edges, which is why techniques such as boundary value analysis and equivalence partitioning exist.
A common misconception is that more test cases always mean better testing. Dozens of cases that check the same happy path add maintenance without finding new bugs. A smaller set that covers distinct behaviors, edge cases and past regressions gives far more confidence.
Key takeaways
- A test case checks one behavior with conditions, steps and an expected result.
- Related test cases are grouped into test suites.
- Arrange, Act, Assert keeps automated test cases readable.
- Good cases cover errors, edge cases and boundaries, not only the happy path.
- Distinct, well-chosen cases beat a large number of similar ones.
Example
import pytest
from shop.coupons import apply_coupon, CouponExpired
def test_applies_ten_percent_coupon():
cart = {"total": 200} # Arrange
result = apply_coupon(cart, "SAVE10") # Act
assert result["total"] == 180 # Assert
def test_rejects_expired_coupon():
with pytest.raises(CouponExpired):
apply_coupon({"total": 200}, "SUMMER2024")
@pytest.mark.parametrize("total", [0, 0.01, 999_999]) # boundaries and extremes
def test_never_goes_below_zero(total):
assert apply_coupon({"total": total}, "SAVE10")["total"] >= 0Readers ask
What is the difference between a test case and a test scenario?
A test scenario is a high-level idea of what to test, such as checking login. Test cases are the specific checks within it, each with exact inputs and expected results, such as a wrong password or an expired account.
What should a test case include?
An identifier or clear name, preconditions, the steps or input, the expected result and, once run, the actual result. Automated cases express the same parts in code.
What is an edge case?
An input or situation at the limits of what the software handles, such as an empty list, the maximum allowed value or a leap day. Edge cases deserve their own test cases because bugs often hide there.
See also
- Unit TestTesting & Quality, p. 35A unit test is a small, automated check that verifies one function, method, or class behaves correctly in isolation from the rest of the program.
- AssertionTesting & Quality, p. 3An assertion is a statement in code declaring that a condition must be true at that point, stopping the test or program with an error if it is false.
- Test FixtureTesting & Quality, p. 31A test fixture is the known state a test needs before it runs, such as sample data or a configured object, plus the code that sets it up and tears it down.
- Acceptance CriteriaTeams & Process, p. 1Acceptance criteria are the specific, testable conditions a single user story or backlog item must meet before the Product Owner accepts it as complete.
- Quality AssuranceTesting & Quality, p. 21Quality assurance (QA) is the set of practices that ensure software meets its requirements and works reliably, aiming to prevent defects, not just find them.
- Behavior-Driven DevelopmentTesting & Quality, p. 4Behavior-driven development is a practice where developers, testers, and business people agree on plain-language examples that become automated tests.
Spotted a mistake or something missing on this page?Suggest an edit