A CVV test case is a documented check that verifies how a payment form or payment API handles the 3 or 4 digit card verification value, covering valid input, invalid formats, empty fields, and mismatch responses. Every CVV test case should run against sandbox test cards issued by your payment processor, never against real cardholder data.
What a CVV test case actually verifies
The CVV field looks trivial on screen, but it sits at the intersection of form validation, tokenization, and fraud rules. A well-built set of test cases confirms four things: the field accepts only the digits it should, the value never lands in logs or storage, the payment gateway returns the right decline reason when the code is wrong, and the UI recovers gracefully when a shopper corrects a typo. Each of those is a separate test case with its own expected result.
The four fields every test case needs
- ID and title so the case can be traced to a requirement or ticket.
- Preconditions such as a sandbox merchant account, a saved test card, or an expired session.
- Steps and test data written as exact inputs, including the specific sandbox card number and CVV value used.
- Expected result stated as an observable outcome, for example an error message, an HTTP status, or a decline code.
A case without a precise expected result is not a test, it is a note. Reviewers should be able to run it without asking a question.
Core scenarios to cover
Format and boundary checks
- Three digits accepted for cards where three is correct; four digits accepted for American Express.
- Fewer digits than required blocks submission with an inline message.
- Letters, spaces, hyphens, and pasted whitespace are rejected or stripped.
- Leading zeros are preserved, for example 007.
- Maximum length enforced on the input, not just validated after typing.
Gateway and API behavior
- Correct card number with an incorrect CVV returns the processor's CVV mismatch decline code.
- Valid data on a sandbox card produces an approval and a token that contains no CVV.
- Declined authorization shows a shopper-friendly message instead of a raw gateway string.
- Retry after a mismatch succeeds once the correct code is entered.
Security and data handling
- The CVV is absent from application logs, analytics events, crash reports, and database rows.
- The value is masked in the UI and cleared after a failed attempt.
- Deep links and browser autofill cannot restore a previously entered CVV.
That last group matters most. PCI DSS forbids retaining the CVV after authorization, so any test that finds a stored or logged code is a release blocker, not a cosmetic bug.
Example test case, written out
Title: CVV mismatch on sandbox Visa card returns decline.
- Open the checkout page with a sandbox merchant account.
- Enter the processor's documented test Visa number and a future expiry date.
- Enter any three-digit code the sandbox documentation lists as a mismatch trigger.
- Submit the payment.
Expected: the order is not created, the page shows a generic decline message, the decline code appears in the processor dashboard, and no CVV value appears in application logs.
Mistakes that weaken a test suite
- Testing only the happy path and never the mismatch decline.
- Hardcoding one card brand, which skips the four-digit Amex rule.
- Using live card numbers in a staging environment, which pulls real cardholder data into scope.
- Checking the database by eye instead of asserting on it in an automated test.
- Recording the CVV in a screenshot attached to the test run.
Keep the suite in the same repository as the checkout code, tag each CVV test case to the requirement it protects, and rerun the security group on every release that touches the payment form.