Assure your AI deployment - across enterprise and real world

We assure that your AI works as intended. Safely and securely.

Testing

What Is Negative Testing? Types, Examples, and Test Cases

Negative testing checks how software handles invalid input. See negative test case examples paired with positive cases, plus types and techniques.

Last Updated on:

Overview

Negative testing is a software testing technique that feeds an application invalid, unexpected, or malicious input, such as letters in an age field or an expired card at checkout, to confirm it rejects the input with a clear error, keeps its data intact, and never crashes. It is the counterpart to positive testing, which checks valid input.

What Does Negative Testing Cover?

  • Invalid input: Negative testing enters blank required fields, wrong data types, out-of-range values, and malformed formats, each of which the application must refuse with an error message that tells the user what to fix.
  • Boundary values: Negative boundary tests use values just outside an allowed limit, such as 0 and 121 for an age field that accepts 1 to 120, where off-by-one validation bugs are most likely to hide.
  • Security input: Security negative tests send SQL injection strings, script tags, and API requests without a valid token, which the application must block without exposing stored data, stack traces, or server details.
  • Positive and negative test cases: A positive case proves a feature works with valid input, and a negative case proves the same feature fails safely with invalid input. Complete coverage writes both from each requirement.

How Do Teams Run Negative Tests on Every Build?

  • Scripted automation: Negative tests repeat on every build, so teams automate them as data-driven tests in a framework such as Selenium, Cypress, or Playwright, feeding many invalid values through one script.
  • AI-generated test cases: KaneAI by TestMu AI generates negative test cases from plain-English descriptions of the invalid inputs, so writing them requires no code.

What Is Negative Testing?

The ISTQB glossary defines negative testing as "a test type in which a component or system is used in a way that it is not intended" and lists invalid testing and dirty testing as synonyms. In practice, a negative test sends input that the requirements say the system must refuse, then checks how the system refuses it.

A negative test passes only when the application does all of the following:

  • Rejects the input and does not process it.
  • Shows an error message that tells the user what to fix, such as "Enter a date in DD/MM/YYYY format", instead of a generic "Something went wrong".
  • Leaves stored data unchanged, with no partial record, no duplicate order, and no charge.
  • Stays up and responsive, with no crash, freeze, or unhandled exception.
  • Reveals nothing internal, such as a stack trace, a raw SQL error, or a server version.

Negative tests belong at every level of software testing, from a unit test that passes null to a function, to an end-to-end test that submits a form with a blank required field. They are a core part of software quality assurance because real users mistype, skip fields, and paste unexpected content, and attackers send malformed input on purpose.

Positive vs Negative Testing: Key Differences

Positive testing checks that software works as expected with valid input, while negative testing checks that it rejects invalid or unexpected input without failing. Most features need both.


AspectPositive TestingNegative Testing
Question it answersDoes the feature do what it should with valid input?Does the feature refuse what it should refuse, safely?
Input usedValid data inside the specified rules.Invalid, out-of-range, malformed, or malicious data.
Expected resultThe task completes and the data is saved.A clear error, no crash, and no change to stored data.
Example: age field that accepts 1 to 120Enter 35 and the profile saves.Enter 0, 121, or "abc" and the form shows "Enter an age from 1 to 120".
Number of casesUsually fewer, one per valid path or valid partition.Usually more, one per broken rule, boundary, and invalid partition.
Defects it findsBroken features and wrong results on valid input.Missing validation, poor error handling, data corruption, and security gaps.
LimitationProves nothing about invalid or unexpected use.Cannot cover every invalid value, so cases must be chosen by risk.

Write positive and negative test cases from the same requirement. The rule "age must be a whole number from 1 to 120" produces positive cases for 1, 35, and 120, and negative cases for 0, 121, -5, 34.5, an empty field, and text. If a requirement does not say what should happen with invalid input, that gap is the first defect to report.

Happy Path vs Positive vs Negative Testing

Happy path testing runs only the default flow a user is expected to follow, while positive testing covers every valid input and alternate path. A checkout that works with a valid card but creates a broken order when the card has expired has passed the happy path and failed real-world use. On Shopify, a Shopify test order in Shopify Payments test mode covers the expired-card case without a real card.


AspectHappy Path TestingPositive TestingNegative Testing
GoalConfirm the primary, expected user journey completes end to end.Confirm the system accepts every valid input, not just the main journey.Confirm the system rejects invalid input and fails safely.
Input usedThe single default, valid flow.A range of valid inputs and valid alternate paths.Invalid, out-of-range, malformed, or malicious inputs.
Typical exampleLog in with a correct email and password.Log in with valid credentials in different valid formats.Log in with a blank password or a SQL injection string.

Negative vs Destructive Testing

Negative testing and destructive testing both use input or conditions the system was not built for, but they ask different questions. A negative test knows the correct outcome in advance, a specific error and unchanged data, and fails if the system does anything else. A destructive test pushes the system until it breaks, by overloading it, killing processes, cutting the network, or corrupting data, to learn where it fails and whether it recovers. Destructive work overlaps with failure testing and chaos testing.


AspectNegative TestingDestructive Testing
GoalConfirm invalid input is rejected gracefully.Find the point where the system fails and check recovery.
Typical input or conditionBlank fields, wrong types, out-of-range values, missing tokens.Extreme load, killed services, corrupted files, network loss.
Expected resultDefined in advance: a specific error and no data change.Often unknown in advance: the test measures how and where it breaks.
Where it runsEvery build, usually inside the automated regression suite.Isolated environments, because the test can damage data.

What Is an Example of Negative Testing?

A common negative testing example is a signup form that requires an 8 to 16 character password, tested with 7-character and 17-character passwords to confirm both are rejected.

The positive tests enter passwords of exactly 8 and 16 characters and expect the account to be created. The negative tests enter 7 and 17 characters, a blank password, and a password made of 16 spaces, and expect the form to refuse each one with a message such as "Password must be 8 to 16 characters". After each refusal, the tester also checks that no account record was created.

These few cases catch two common defects. A length check written as "less than 16" instead of "16 or fewer" rejects a valid 16-character password, which only the positive boundary case reveals. A check that runs only in the browser lets a 17-character password through when the same request is sent straight to the API, which only a backend negative test reveals.

Negative Test Case Examples With Positive Counterparts

The table below pairs common negative test cases with the positive case written from the same requirement. Each test case lists the steps, the test data, and an expected result precise enough to fail. The error text is an example: use the exact wording in your requirements so the test can assert it.


Negative test caseStepsTest dataExpected resultPositive counterpart
Login with a blank passwordEnter a registered email, leave the password empty, select Log in.Email: qa.user@example.com, password: empty"Password is required" appears under the field. No session is created.The same email with the correct password opens the dashboard.
Login after repeated wrong passwordsEnter a wrong password more times than the lockout limit in the spec.Password: Wrong#Pass1, repeated"Too many attempts. Try again in 15 minutes." The correct password is also refused until the lockout ends.The correct password on the first attempt logs in.
Signup with an email that already has an accountSubmit the signup form with an existing account email.Email: existing.user@example.com"An account with this email already exists". No second account is created.A new, unused email creates one account and sends one verification email.
Signup below the minimum ageEnter a date of birth that makes the user younger than the minimum age in the spec.Date of birth: 12 years before today, with a minimum age of 13"You must be 13 or older to sign up". No record is saved.A date of birth exactly 13 years before today is accepted.
Age field with out-of-range and non-numeric valuesEnter each value in an age field that accepts 1 to 120, then select Save.0, 121, -5, 34.5, thirty"Enter a whole number from 1 to 120" for every value. The saved age does not change.1, 35, and 120 each save.
Profile photo with a disguised file typeRename a ZIP archive to photo.jpg and upload it.photo.jpg containing ZIP dataThe server checks the file content, not only the extension: "Upload a JPG or PNG image". Nothing is stored.A real 2 MB JPG uploads and displays.
File over the size limitUpload an image larger than the limit in the spec.25 MB PNG, with a 10 MB limit"File must be 10 MB or smaller". The upload stops and the page stays responsive.A 9 MB PNG uploads.
Checkout with an expired cardEnter a card whose expiry month has passed and place the order.Expiry: last month"Your card has expired". No order is created and no charge is made.A valid sandbox card places one order and sends one confirmation.
Card number that fails the checksumEnter a 16-digit card number with the last digit changed.4111 1111 1111 1112"Enter a valid card number" before submission. No call reaches the payment gateway.A standard Visa test number such as 4111 1111 1111 1111 is accepted by the payment sandbox.
Search with an injection-style stringType the string into the search box and submit.' OR '1'='1A normal "No results" page or literal matches. No database error and no extra records.Searching for an existing product name returns that product.
Protected page after logoutLog out, then select Back or paste the account URL./account/ordersRedirect to the login page. No cached order data is shown.A logged-in user sees the order list.
API request without a tokenSend GET /api/orders with no Authorization header.No token401 Unauthorized with a JSON error body. No order data is returned.A valid token returns 200 OK and only that user's orders.
API request with malformed JSONSend POST /api/orders with a missing closing brace.{"item": "A1", "qty": 2400 Bad Request with a validation message. No 500 error and no stack trace.Valid JSON creates the order and returns 201 Created.

Negative Test Cases for a Messaging App Such as WhatsApp

A messaging app combines text input, contact permissions, media upload, and an unreliable network, so it needs negative cases at each of those points. These rows fit any chat app, including WhatsApp-style apps. Take the limits and the error wording from the app under test, not from this table.


Negative test caseTest data or conditionExpected resultPositive counterpart
Send an empty messageMessage box empty, or only spaces and line breaksSend stays disabled or nothing is sent. No blank message appears in the chat.Typing a word enables Send and delivers the message.
Send an oversize messagePasted text longer than the character limit of the appThe text is blocked, trimmed, or split as the spec says, with a visible notice. The app does not freeze.A message under the limit is delivered in full.
Message a contact you blockedOpen the chat of a blocked contact and type a messageThe app asks you to unblock the contact first. Nothing is delivered.After unblocking, the same message is delivered.
Send while offlineAirplane mode on, then send a messageThe message shows a pending state and sends once when the connection returns, with no duplicate.Online, the message shows as sent straight away.
Attach an unsupported or oversize fileA file type or size outside the allowed listA clear file type or size error. The chat stays usable.An allowed photo sends and shows a preview.
Post in a group after being removedA removed member opens the group and tries to sendInput is disabled with a notice that the user is no longer a participant. Nothing reaches the group.Current members can send and receive.
Test your website on the TestMu AI real device cloud

What Are the Types of Negative Testing?

The main types of negative testing are boundary value testing, input validation testing, invalid equivalence class testing, data type and format testing, security and injection testing, and error handling testing.

Boundary Value Testing

Boundary value testing enters values just outside each limit, with the limits themselves as positive controls. For a quantity field that accepts 1 to 100, the negative values are 0 and 101, and the positive values are 1 and 100. Validation code often fails at these edges because a comparison uses the wrong operator. Boundary value analysis explains how to pick the values systematically.

Input Validation Testing

Input validation testing breaks each rule a form or API applies before it accepts data. Most rules fall into five checks, and each needs at least one negative case:

  • Presence check - Leave a required field blank and submit.
  • Range check - Enter a value below the minimum or above the maximum.
  • Length check - Enter one character more than the field allows, or paste text past a maxlength limit.
  • Format check - Enter a value that breaks the pattern, such as an email without a domain or a phone number with letters.
  • Consistency check - Enter related fields that contradict each other, such as an end date before the start date.

Invalid Equivalence Class Testing

Invalid equivalence class testing splits the invalid input into groups that the system should treat the same way, then tests one value from each group instead of every value. For an age field that accepts 1 to 120, the invalid classes are numbers below 1, numbers above 120, decimals, text, and an empty field, so five cases cover them. The method comes from equivalence partitioning, applied to the invalid partitions.

Data Type and Format Testing

Data type and format testing sends values of the wrong kind: letters in a numeric field, an impossible date such as 31/02/2026, a month of 13, emoji or control characters in a name field that forbids them, and leading or trailing spaces. It finds fields that accept bad data silently and then fail later, in a report, an export, or a calculation.

Security and Injection Testing

Security negative tests send input written to attack the application: SQL injection strings, script tags that attempt cross-site scripting, file names with path traversal such as ../../config, requests with expired or missing tokens, and URLs with the record ID of a different user swapped in. The expected result is always a refusal or escaped output, with no data exposed. These cases are the bridge between negative testing and full security testing.

Error Handling and Fault Injection Testing

Error handling testing makes a dependency fail on purpose: the database goes down, a third-party API times out, the disk fills, or the network drops mid-request. The application should show a controlled error, retry or roll back the transaction as designed, and log the failure. Mocking tools simulate these faults without breaking shared environments.

Which Techniques Are Used for Negative Testing?

The core negative testing techniques are boundary value analysis, equivalence partitioning, error guessing, state transition testing, fuzz testing, fault injection, and exploratory testing.


TechniqueWhat it findsExample negative input
Boundary value analysisOff-by-one errors at the edges of a range or length limit.0 and 101 in a field that accepts 1 to 100.
Equivalence partitioningWhole classes of invalid input the code does not handle.One decimal, one negative number, and one text value in a whole-number field.
Error guessingDefects the requirements never mention, based on past bugs.A double click on Pay, or a name pasted with a trailing space.
State transition testingActions accepted in a state where they should be blocked.Shipping an order that was already cancelled.
Fuzz testingCrashes, hangs, and memory errors on random or malformed input.Thousands of mutated JSON bodies sent to one endpoint.
Fault injectionMissing timeouts, retries, and rollbacks when a dependency fails.A payment API stub that returns 503 or never responds.
Exploratory testingUnexpected paths that scripted cases miss in new features.Pressing Back halfway through a multi-step form, then resubmitting.

Use boundary value analysis and equivalence partitioning to derive the systematic cases from requirements, then add error guessing and exploratory sessions for the cases requirements forget. Fuzz testing works differently from the rest: there is no single expected error, and a run passes when nothing crashes, hangs, or leaks memory.

How Do Frontend and Backend Negative Test Scenarios Differ?

Frontend negative tests check that the UI blocks bad input such as script tags and oversized files, while backend tests send malformed payloads and invalid tokens straight to the API.

Split negative test scenarios by layer so a working UI check does not hide a missing server-side check. Browser validation improves the user experience, but anyone can bypass it, so the server must enforce every rule again.

Frontend Negative Test Scenarios

  • Entering invalid characters such as emojis, control characters, or script tags into text fields to check input sanitization and Cross-Site Scripting (XSS) protection.
  • Bypassing UI limits by pasting more text than a maxlength field allows or forcing a disabled button to active through the browser console.
  • Rapid double-clicking a submit button to trigger duplicate requests, race conditions, or double charges.
  • Uploading a file of the wrong type or size, or an empty file, to confirm client-side validation rejects it with a clear message.

Backend Negative Test Scenarios

  • Sending malformed JSON payloads, missing required fields, or wrong data types to confirm the API returns a controlled validation error instead of a stack trace.
  • Attempting SQL injection strings in query parameters and request bodies to confirm inputs are parameterized and the database is protected.
  • Verifying correct API response codes, so a missing resource returns a 404 error and an unhandled fault returns a 500 Internal Server Error rather than leaking internal details.
  • Sending requests without a valid token or with an expired one to confirm authentication and authorization return 401 or 403 as expected.

How Do You Design and Perform Negative Testing?

Design and run negative tests by listing the validation rules, deriving invalid inputs, writing exact expected results, preparing test data, executing and checking system state, automating stable cases, and logging failures as defects.

  • List the rules - From the requirements, user stories, and API specification, write down every rule an input must satisfy: required fields, lengths, ranges, formats, allowed file types, and permissions. Each rule needs at least one negative case.
  • Derive the invalid inputs - Apply boundary value analysis and equivalence partitioning to each rule, then add error-guessing cases from defects found in similar features.
  • Write the expected result precisely - Name the exact error message or HTTP status code, and the state that must not change, such as no new record, no charge, and no email sent. "Shows an error" is too vague to fail.
  • Prepare the test data - Keep invalid values in a data file next to the valid ones, so one script can loop through both. Our guide to test data covers how to build and maintain these sets.
  • Execute and check the state - Run each case, compare the actual result with the expected one, then look past the screen at database rows, logs, sent emails, and outgoing API calls.
  • Automate the stable cases - Move repeatable negative tests into a data-driven test inside the regression testing suite, and keep exploratory negative testing manual for new features.
  • Log failures as defects - Record the exact input, the expected error, and the actual behavior so a developer can reproduce the failure. Rate crashes, data corruption, and security exposure as critical and a confusing error message as minor, then follow your usual defect management process through the defect life cycle.

How Do You Set Up a Test Environment for Negative Testing?

Set up a negative testing environment that matches production configuration, uses resettable test data, and includes tools for test management, automation, API requests, and mocking.

Run negative tests in a test environment whose configuration matches production, because validation rules, error pages, upload limits, and timeouts can differ between environments. Use dedicated test accounts and a database you can reset, since a negative test that unexpectedly passes invalid data through leaves junk records behind.

  • Test management - Store each negative case next to its positive pair in test management tools such as TestRail or qTest, so the test coverage of each requirement is visible.
  • UI automation - Selenium, Cypress, and Playwright drive the browser through invalid input and assert the error text.
  • API tools - Postman or REST Assured send malformed requests, missing tokens, and wrong methods straight to the backend, as covered in API testing.
  • Mocking and stubbing - Mockito and WireMock simulate a failing or slow dependency for error handling and fault injection tests.

What Are the Benefits of Negative Testing?

Negative testing finds missing validation early, protects stored data, catches security regressions, improves error messages, and prevents crashes caused by ordinary user mistakes.

  • Earlier defect detection - Negative cases written from requirements expose missing validation rules before release, when the fix is a code change rather than a cleanup of bad production data.
  • Data integrity - Rejected input never reaches the database, so reports, invoices, and downstream systems do not inherit corrupt records.
  • Security regression checks - Injection attempts, missing token checks, and requests for records owned by other users are negative tests by nature, and running them on every build catches a control that a refactor removed.
  • Clearer error messages - Asserting the exact error text pushes teams to write messages that tell users what to fix.
  • Fewer crashes from user mistakes - Blank fields, double clicks, and pasted text are everyday user behavior, and testing them prevents avoidable crashes and support tickets.

What Are the Challenges in Negative Testing?

The main challenges in negative testing are an unlimited input space, the extra time it takes, vague expected results, hard-to-reproduce timing scenarios, and test data upkeep.

  • Unlimited input space - No team can test every invalid value, and some are too unlikely or harmless to be worth a case. Choose cases with partitions and boundaries, and rank features with risk-based testing.
  • Time and effort - A feature usually needs more negative cases than positive ones, which adds design and execution time.
  • Vague expected results - When requirements do not define error behavior, testers cannot judge pass or fail. Raise the gap with the product owner instead of guessing.
  • Timing scenarios - Timeouts, race conditions, and double submissions are hard to reproduce reliably and often need fault injection tools.
  • Test data upkeep - Invalid data sets and the environment resets they depend on must change whenever validation rules change.

What Are the Best Practices for Negative Testing?

Negative testing works best when every positive case has negative partners, every expected result names the exact error and the unchanged state, and the riskiest features get the most cases.

  • Pair cases by requirement - Write the negative cases at the same time as the positive case for each rule, so no rule ships with only its happy path tested.
  • Assert the error and the state - Check the error text or status code and confirm that nothing was saved, charged, or sent.
  • Test both layers - Repeat key negative cases against the API, because browser validation alone can be bypassed.
  • Start with high-risk features - Payments, authentication, permissions, and anything that writes data get negative cases first.
  • Use real bad input - Mine rejected-input logs and support tickets for the invalid values real users actually send.
  • Automate the repeatable cases - Run stable negative tests on every build and keep exploratory sessions for new features.

How Is AI Changing Negative Testing?

AI is changing negative testing by generating invalid inputs, boundary values, and malformed payloads from requirements and API specs, including edge cases testers often miss.

Writing many invalid-input cases by hand is slow, which is why teams pair negative testing with AI authoring. With KaneAI, you describe the invalid inputs and edge cases in plain English, and the agent generates the executable negative test cases, proposes smart assertions for the expected error handling, and runs them across the TestMu AI grid of 3,000+ browser and OS combinations and 50,000+ real devices. Generated tests export to Selenium, Playwright, Cypress, or Appium, so your team keeps its existing framework.

Review every AI-generated negative test against the real business rules, since a model can propose inputs the system should accept or expect the wrong error message. Our roundup of AI test case generation tools compares the options.

AI features need negative tests too. Apps built on large language models are tested with adversarial prompts, prompt injection attempts, and out-of-scope requests to confirm the model refuses them or fails safely. Prompt injection tops the OWASP Top 10 for LLM Applications, which makes these checks a core part of LLM testing.

If the AI feature is a chatbot, a set of ready-made chatbot test cases covers inputs it should refuse or deflect, from out-of-scope questions to prompt injection.

Where Should You Start With Negative Testing?

Start negative testing with the inputs users most often get wrong, such as blank required fields, wrong data types, and out-of-range values, then automate those checks in CI.

Pick the form or API endpoint that writes your most important data, list its validation rules, and write one negative case per rule beside its positive case, using the example table above as a template. Once those cases pass by hand, move them into a data-driven automated test that runs on every build.

Run tests up to 70% faster on the TestMu AI cloud grid

Testing web or mobile apps without writing code? KaneAI by TestMu AI turns plain-English instructions into tests.

To run your first test, start free, or
for a full walkthrough of the product.

Author

...

Nazneen Ahmad

Blogs: 37

  • Twitter
  • Linkedin

Nazneen Ahmad is a freelance Technical Content SEO Writer with over 6 years of experience in crafting high ranking content on software testing, web development, and medical case studies. She has written 60+ technical blogs, including 50+ top-ranking articles focused on software testing and web development. Certified in Automation Basic and Advanced Training - XO 10, she blends subject knowledge with SEO strategies to create user focused, authoritative content. Over time, she has shifted from quick, keyword-heavy drafts to producing content that prioritizes user intent, readability, and topical authority to deliver lasting value.

Reviewer

...

Shahzeb Hoda

Reviewer

  • Linkedin

Shahzeb Hoda is the Associate Director of Marketing and a Community Contributor at TestMu AI, leading strategic initiatives in developer marketing, content, and community growth. With 10+ years of experience in quality engineering, software testing, automation testing, and e-learning, he has authored and reviewed 70+ technical articles on software testing and automation. Shahzeb holds an M.Tech in Computer Science from BIT, Mesra, and is certified in Selenium, Cypress, Playwright, Appium, and KaneAI. He brings deep expertise in CI/CD pipeline automation, cross-browser testing, AI-driven testing practices, and framework documentation. On LinkedIn, he is followed by 3,700+ engineers, developers, DevOps professionals, tech leaders, and enthusiasts.

Add to Google preferred sources

Summarise with AI

Copied to Clipboard!
...

3000+ Browsers. One Platform.

See exactly how your site performs everywhere.

Try it free
...

Write Tests in Plain English with KaneAI

Create, debug, and evolve tests using natural language.

Try for free

Negative Testing FAQs

Did you find this page helpful?

More Related Learning Hubs

TestMu AI forEnterprise

Get access to solutions built on Enterprise
grade security, privacy, & compliance

  • Advanced access controls
  • Advanced data retention rules
  • Advanced Local Testing
  • Premium Support options
  • Early access to beta features
  • Private Slack Channel
  • Unlimited Manual Accessibility DevTools Tests