~/qa-guides

~/qa-guides/equivalence-partitioning

>_ Equivalence Partitioning: Examples and Test Cases

Define equivalence classes, choose representatives, and measure coverage with three models and 15 worked cases, including missing values, types, and field combinations.

Test designEquivalence classesTest casesCoverage

Published

Short answer

Equivalence partitioning (EP) is a black-box test design technique that groups data into classes expected to follow the same handling rule. A tester chooses representative values from those classes and compares the observed results with the requirement.

The useful work is defining the groups: which values belong together, which require different treatment, and what each selected input should produce. Testing one representative is a coverage choice based on that model, not proof that every other member behaves correctly.

This guide develops three examples: an integer booking field, an unordered export-format choice, and a request containing several fields. It includes coverage calculations and 15 worked test cases, with explicit rules for missing values, nulls, types, normalization, and combinations.

What makes inputs an equivalence class?

The ISTQB Foundation Level syllabus v4.0.1, section 4.2.1, describes partitions based on expected common processing. Classes may be ordered or unordered, and each class must be nonempty and not overlap another class in the same partition set.

Common processing does not require identical response bytes. Two accepted seat counts can be saved as different numbers while following the same booking-tier rule. Two labels can retain different text while following the same trimming and acceptance rule.

Define equivalence relative to the behavior being tested. Grouping all accepted export formats together might answer a narrow acceptance question, but it loses the distinction between the CSV, JSON, and PDF rendering outcomes used in the example below.

For the wider distinction between specification-based and structure-based design, see Black-Box vs White-Box Testing. EP selects inputs from the agreed behavior rather than copying the implementation's current branches as the expected rules.

How to derive equivalence partitions from requirements

1. State the domain and the observation

Name the object being classified, such as an integer seat count, a parsed field value, or a supported format identifier. State what is already assumed to have passed before that classification begins.

An integer-only model does not automatically classify strings, missing properties, or malformed requests. A model of decoded values does not establish how invalid input bytes are handled. Those conditions need their own defined scope.

Also specify the observation: acceptance, selected tier, saved data, renderer, error code, or another result. Without it, a partition can become a vague collection of values that look similar to the author.

2. Find the rules that change treatment

List each reason the product accepts, rejects, transforms, or routes data differently. Include valid alternatives as well as invalid inputs.

A single accepted range may need more than one valid class when the requirement changes the business outcome inside it. Conversely, different spellings may belong together after an explicitly required normalization.

Do not invent classes solely because inputs look different. Explain the processing expectation that makes the grouping useful, and record any uncertainty as a requirement question.

3. Write membership rules that do not overlap

Give each class an identifier and a predicate that another tester can apply. Check that selected values belong to exactly one class within the declared set.

Where validation rules overlap, make the classification order explicit. A string can be both overlong and contain a forbidden character. The label model below uses a defined precedence so that one combined defect is not counted as evidence for two independently exercised validation rules.

Across different partition sets, the same input can have several classifications. There is no contradiction in classifying a value by type in one set and by business eligibility in another, provided the sets and their coverage are reported separately.

4. Check for gaps and empty classes

Test the predicates against ordinary examples, awkward representations, and the edges between groups. Check omitted fields, nulls, zero, empty text, and other relevant values deliberately rather than adding them as an unstructured final list.

Remove a class that cannot contain any value under the declared domain, or correct the domain if the class represents a real requirement. Identify values that match no predicate before calling the model complete.

Completeness applies to the stated model. Do not quietly expand an integer model into a claim about every input accepted by a network endpoint.

5. Choose representatives and independent expectations

Choose an ordinary representative whose membership is easy to explain. Record its expected outcome before running the implementation.

For one invalid field, keep other fields, permissions, and setup valid. This reduces the chance that a different rejection hides the behavior being investigated.

Add more members from a class when they target a meaningful implementation risk, such as trimming, coercion, or a special parser path. They may improve defect detection without increasing the partition coverage count.

6. Map executions to classes and remaining risks

Record which selected input exercises which class, then update that record with observed evidence. Distinguish data present in a request from validation behavior that was actually reached.

Measure coverage against the inventory, not against the number of test cases. Repeating one valid class ten times does not cover ten classes.

Keep separate notes for boundaries, combinations, state history, and unsupported input domains. A useful EP model makes those remaining questions visible instead of absorbing every testing technique into one percentage.

Worked example 1: Integer booking quantities

Define the booking rule and four classes

For this example, the domain is integer seat counts. A booking service accepts 1 through 50 seats. Counts 1 through 9 create a standard-tier booking; counts 10 through 50 create a group-tier booking. An accepted booking stores the exact submitted seat count.

Counts below 1 are rejected with quantity_below_minimum; counts above 50 are rejected with quantity_above_maximum. A rejection creates no booking. Inventory, actor permissions, and other fields are valid.

The partition set is:

  • N1: Integers at or below 0; reject below the minimum. Representative: -2.
  • N2: Integers from 1 through 9; create a standard-tier booking. Representative: 4.
  • N3: Integers from 10 through 50; create a group-tier booking. Representative: 16.
  • N4: Integers at or above 51; reject above the maximum. Representative: 75.

These classes cover every integer exactly once. A value such as 9 belongs to N2, 10 belongs to N3, and neither belongs to both. A noninteger such as 2.5 is outside this particular domain and needs a separate schema or type expectation.

Calculate coverage and distinguish another representative

Tests using only 4 and 16 exercise N2 and N3: 2 / 4 = 50% coverage of this four-class inventory. The two valid classes are covered, but the invalid classes are not.

Adding -2 and 75 covers the remaining classes, giving 4 / 4 = 100% partition coverage. Each rejection must still produce its required error and leave the booking count unchanged.

Adding 6 after 4 is another N2 representative. It does not increase the number of covered classes. It might reveal a defect affecting 6, but that is different from covering an additional requirement-defined partition.

The four representatives do not check exact tier changes at 9 and 10 or acceptance limits at 1 and 50. The Boundary Value Analysis guide shows how to derive the additional ordered-edge inputs. EP and boundary analysis answer related selection questions at different levels.

Worked example 2: Unordered export formats

Define the format domain and required outputs

This model classifies nonempty strings supplied as format identifiers. Schema checks for absent, null, empty, or non-string format values are outside this set. Format names are case-sensitive and are not trimmed.

The test report contains one known source record: reference R17 with numeric value 42. The supported identifiers are csv, json, and pdf. Each accepted export creates one job and one artifact containing that record through the selected renderer.

  • F1: Exactly csv; produce the CSV artifact with the reference and value fields.
  • F2: Exactly json; produce the JSON artifact preserving reference R17 and numeric value 42.
  • F3: Exactly pdf; produce the PDF artifact displaying reference R17 and value 42.
  • F4: Every other nonempty string; reject with format_unsupported and create no job or artifact.

The valid classes happen to contain one identifier each. A partition can be a singleton; reducing the number of values within every valid class is not a requirement for the model to be useful. The unsupported class includes many strings.

Select representatives without inventing numeric edges

Use csv, json, pdf, and xml to cover the four classes. The strings CSV and csv also belong to F4 under the explicitly strict matching rule, even if a different product would normalize them.

Alphabetical positions between format names have no relevant business meaning here. A neighboring string in a sorted list is not a justified boundary test for the format-selection rule.

Inspect output behavior, not only a success indicator. A defect that renders every accepted format as CSV could satisfy an acceptance-only assertion while violating F2 and F3. That is why this model's classes include the required processing outcome.

Worked example 3: Several fields in an export request

Define the request and its validation order

Extend the export example with delivery and label fields. Format and delivery have already passed envelope checks requiring nonempty strings. Label may be any parsed JSON value or an omitted property, so its classes include missing, null, and wrong-type conditions.

Validation evaluates format, then delivery, then label, stopping at the first failure. An unsuccessful request creates no job, artifact, or delivery event. Valid requests create one job and one correct-format artifact containing R17 and 42.

Download delivery exposes the permitted artifact reference without an email event. Email delivery emits one message to a controlled test adapter. Every supported format is permitted with either delivery method; there is no hidden PDF-and-email restriction in this example.

Define delivery classes

Keep the four format classes F1-F4 and add this delivery set:

  • D1: Exactly download; make the artifact available through the permitted download result.
  • D2: Exactly email; emit one delivery message through the test adapter.
  • D3: Every other nonempty string, such as fax; reject with delivery_unsupported.

Delivery names are also case-sensitive and not trimmed. Their missing, empty, null, and wrong-type envelope conditions are outside this three-class set. Report that scope alongside coverage rather than implying those cases were tested.

Define seven mutually exclusive label classes

Label is required and must be a string. Remove surrounding ASCII space characters only; do not remove tabs or collapse internal spaces. The normalized nonempty string may contain ASCII letters and spaces and must be no longer than 12 characters.

For strings, check emptiness first, allowed characters second, and length third. On acceptance, store the normalized label exactly. The class definitions are:

  • L1: The property is omitted; reject with label_required.
  • L2: The property is present with JSON null; reject with label_null.
  • L3: A present non-null value is not a string; reject with label_type. Numbers, booleans, arrays, and objects belong here.
  • L4: A string becomes empty after the stated space trimming; reject with label_empty.
  • L5: A nonempty normalized string contains a character other than an ASCII letter or space; reject with label_characters.
  • L6: A nonempty normalized string uses only allowed characters but contains at least 13 characters; reject with label_length.
  • L7: A normalized string uses only allowed characters and contains 1 through 12 characters; accept and store it.

An empty string and a string of spaces share L4 because this contract gives them the same normalized result and error. A tab-only string belongs to L5: tabs are not removed by the specified trimming rule. A literal string null belongs to L7, while JSON null belongs to L2.

A string containing 13 characters including a digit belongs only to L5. It does not also belong to L6, whose predicate requires all characters to be allowed. This avoids overlapping classes while preserving a separate length test using 13 permitted letters.

Cover each valid class without covering every combination

For multiple fields, Each Choice coverage exercises each class in each included partition set at least once. It does not establish coverage of combinations between those classes.

Consider these three independently valid requests, all with label Team:

  • Request C1: Format csv, delivery download, label Team; covers F1, D1, and L7.
  • Request C2: Format json, delivery email, label Team; covers F2, D2, and L7.
  • Request C3: Format pdf, delivery download, label Team; covers F3, D1, and L7.

The valid-class inventory contains three format classes, two delivery classes, and one label class: six items. These requests exercise all six, giving 6 / 6 = 100% valid-class Each Choice coverage.

The valid class combinations number 3 x 2 x 1 = 6. Only three combinations were selected: 3 / 6 = 50% combination coverage. CSV with email, JSON with download, and PDF with email remain untested.

An implementation that incorrectly rejects PDF with email can pass C1-C3. Every valid class was represented, yet the faulty interaction was never attempted. Add targeted combination tests when such interactions matter.

Use Pairwise Testing: Examples and Test Cases to select complete configurations that cover pairs of values across fields, account for constraints, and audit the resulting coverage.

Include invalid classes and define what was exercised

The complete declared inventory contains four format classes, three delivery classes, and seven label classes: 14 items. The three valid requests cover six of those 14 items, or 42.9% rounded to one decimal place.

To complete that inventory with isolated negative evidence, add F4 with other fields valid, D3 with other fields valid, and L1-L6 with valid format and delivery. These eight negative executions plus C1-C3 give an illustrative 11-execution set covering all 14 declared classes.

Eleven is not a universal test-count formula. Different class inventories, dependencies, validation behavior, or coverage criteria change the required selection. This model also excludes the format and delivery envelope variants stated above.

Because validation stops at the first failure, placing unsupported format, unsupported delivery, and null label into one request does not demonstrate all three validation outcomes. Record which behavior was reached and use independent negative executions for the later fields.

Fifteen worked equivalence partitioning test cases

Run independent cases and variants with fresh result baselines. Numeric cases use the booking model; export cases use source record R17 with value 42. Unless a case changes them, export delivery is download and label is Team. Format and delivery satisfy the declared nonempty-string envelope scope.

Test case 1: Select a representative from the standard booking class

  • Preconditions: The caller can create bookings, stock is sufficient, and unrelated fields are valid.
  • Input: Integer seat count 4, class N2.
  • Steps: Submit one booking request, then retrieve the booking created by that request.
  • Expected result: Exactly one standard-tier booking is created with seat count 4.
  • Coverage evidence: N2 is exercised. Do not count the different persisted number as a new class when another accepted standard-tier value is tested.

Test case 2: Exercise the other valid booking tier

  • Preconditions: A fresh valid booking setup with no prior result from this execution.
  • Input: Integer seat count 16, class N3.
  • Steps: Submit once and inspect the saved booking's count and tier.
  • Expected result: Exactly one group-tier booking is created with seat count 16.
  • Coverage evidence: The valid N3 outcome is verified independently of N2. A generic success assertion would miss a service that incorrectly assigns the standard tier.

Test case 3: Reject the below-minimum integer class

  • Preconditions: Permissions, inventory, and other booking fields are valid; record the initial booking count.
  • Input: Integer seat count -2, class N1.
  • Steps: Submit once and inspect the response and any booking associated with this request.
  • Expected result: The request returns quantity_below_minimum and creates no booking.
  • Coverage evidence: Rejection is attributable to N1 rather than another invalid field. Record the unchanged business-result count as well as the error.

Test case 4: Reject the above-maximum integer class

  • Preconditions: A fresh otherwise valid booking request and a recorded result baseline.
  • Input: Integer seat count 75, class N4.
  • Steps: Submit and inspect both the error and resulting booking data.
  • Expected result: The request returns quantity_above_maximum and creates no booking.
  • Coverage evidence: N4 completes the four-class numeric inventory when combined with cases 1-3; it does not establish boundary coverage at 50 or 51.

Test case 5: Verify the CSV format class

  • Preconditions: The report contains only the agreed R17 record; delivery is download and label is Team.
  • Input: Format csv, class F1.
  • Steps: Request the export, wait for its documented completion, and retrieve the resulting artifact.
  • Expected result: One CSV artifact contains the reference and value fields with R17 and 42; no email delivery event is emitted.
  • Coverage evidence: Verify parsed report data and selected format rather than trusting only a filename ending in csv.

Test case 6: Verify the JSON format class

  • Preconditions: The same known report data in an independent execution with valid download delivery and label.
  • Input: Format json, class F2.
  • Steps: Create the export and inspect its completed artifact through the supported read path.
  • Expected result: One JSON artifact represents reference R17 and numeric value 42; the job records format json and no email delivery occurs.
  • Coverage evidence: A CSV body renamed with a different extension does not satisfy the required F2 processing outcome.

Test case 7: Verify the PDF format class

  • Preconditions: A fresh export baseline with the known report record and functioning PDF processing.
  • Input: Format pdf, class F3, with download delivery and label Team.
  • Steps: Create the export, observe completion, and open the intended artifact using the supported viewer or inspection tool.
  • Expected result: One PDF artifact displays reference R17 and value 42, with no extra artifact or email event.
  • Coverage evidence: Observe the rendered report content as well as the job's format field.

Test case 8: Reject unsupported format representatives

  • Preconditions: Delivery is download and label is Team; all envelope conditions pass.
  • Input variants: xml, CSV, and the string csv , each in an independent request.
  • Steps: Submit each request and inspect its validation result and export-side effects.
  • Expected result: Each returns format_unsupported and creates no job, artifact, or delivery event.
  • Coverage evidence: All three inputs belong to F4 under strict matching. They provide additional matching-risk probes without adding three classes to the inventory.

Test case 9: Distinguish omission from JSON null

  • Preconditions: Format csv and delivery download are valid; use fresh execution baselines.
  • Input variants: Omit the label property entirely for L1; include label with JSON null for L2.
  • Steps: Submit each serialized request and inspect the returned field error and job count.
  • Expected result: Omission returns label_required; present null returns label_null. Neither request creates a job, artifact, or delivery event.
  • Coverage evidence: Capture the actual request representation so a client that silently omits null values cannot make the two variants appear equivalent.

Test case 10: Reject wrong types without coercing them to text

  • Preconditions: Format csv and delivery download are valid.
  • Input variants: Label as JSON number 123, boolean true, an empty array, and an empty object; separately, label as the string null.
  • Steps: Submit each independently and inspect the validation outcome or saved normalized label.
  • Expected result: The four non-null non-string values return label_type with no export effects. The four-letter string null is accepted and stored as that text.
  • Coverage evidence: The wrong-type variants exercise L3; the literal string exercises L7. Accepting boolean true by converting it into the string true violates this example's type rule.

Test case 11: Group empty and space-only strings by the stated rule

  • Preconditions: Format csv and delivery download are valid.
  • Input variants: An empty label string and a label containing three ASCII spaces.
  • Steps: Submit each separately after recording the actual input string.
  • Expected result: Both normalize to empty and return label_empty, with no job, artifact, or delivery event.
  • Coverage evidence: Both are L4 representatives. These two executions test the normalization path, but they do not cover two different classes under this contract.

Test case 12: Separate character rejection, length rejection, and acceptance

  • Preconditions: Other export fields are valid and each variant starts with a fresh result baseline.
  • Input variants: Team7; 13 letters ABCDEFGHIJKLM; 13 characters ABCDEFGHIJKL7; and the space-padded string Team .
  • Steps: Submit each independently and inspect the first label error or normalized accepted label.
  • Expected result: Team7 and ABCDEFGHIJKL7 return label_characters through L5. ABCDEFGHIJKLM returns label_length through L6. The padded Team value reaches L7 and is saved as Team.
  • Coverage evidence: The mixed overlong and invalid-character input does not replace the clean L6 fixture, because character validation stops it first.

Test case 13: Demonstrate valid-class Each Choice coverage

  • Preconditions: The report and delivery adapter are available; label Team is valid for every request.
  • Inputs: Independently execute C1 with csv and download, C2 with json and email, and C3 with pdf and download.
  • Steps: Inspect each job, its correct-format artifact, and its delivery result, then map the executions to the valid class IDs.
  • Expected result: Each request creates one job and one correct artifact. Only C2 emits one email-adapter event; C1 and C3 expose the permitted download result.
  • Coverage evidence: The selection covers F1-F3, D1-D2, and L7: all six valid classes, but only three of the six valid class combinations.

Test case 14: Exercise the combinations omitted by that selection

  • Preconditions: All supported formats are permitted with both delivery methods; use label Team and independent request baselines.
  • Input variants: CSV with email, JSON with download, and PDF with email.
  • Steps: Execute each variant and inspect both the format-specific artifact and the delivery result.
  • Expected result: Every variant succeeds. CSV and PDF email variants each emit one adapter event; the JSON download variant emits none and returns its permitted artifact reference.
  • Coverage evidence: Combined with C1-C3, these variants cover all six valid format-and-delivery combinations. A PDF-email rejection is a defect even though F3 and D2 were previously covered separately.

Test case 15: Unmask invalid fields before claiming their validation coverage

  • Preconditions: The endpoint uses format, delivery, then label validation order and stops on the first failure.
  • Inputs: First send xml, fax, and null label together. Then isolate delivery fax with format csv and label Team. Finally isolate null label with format csv and delivery download.
  • Steps: Run each as a separate request, inspect the first error, and compare job, artifact, and delivery counts with their baselines.
  • Expected result: Errors are format_unsupported, delivery_unsupported, and label_null respectively. No request creates export effects.
  • Coverage evidence: The mixed-invalid request demonstrates F4's rejection, not independent proof of D3 or L2 validation. The isolated delivery request supplies the missing D3 evidence.

These cases cover all four numeric classes and all 14 declared export-request classes. Some cases contain independent variants, so 15 case descriptions do not mean 15 executions. Keep the case count, representative count, and class count as separate quantities.

Review assumptions when members behave differently

Distinguish an implementation defect from a model change

Suppose seat count 4 creates a standard booking, while 6 is rejected. Both satisfy N2 under the stated requirement. Record the rejection as a defect; do not redraw the expected class around the implementation's failure to make the tests pass.

If an approved requirement instead introduces a genuine difference, such as separate handling for another category or configuration, update the model and explain the new basis for membership. Revisit representatives and the denominator together.

Preserve a representative that exposed a defect as a regression case. A class can have several useful tests even when only one is needed to mark that class as exercised under the selected coverage criterion.

Add risk-focused representatives without inflating coverage

A number, a boolean, an array, and an object share L3's required label_type outcome, but an implementation might coerce them through different paths. Extra representatives help investigate that risk without changing the declared equivalence-class count.

Likewise, the empty string and the space-only string exercise different raw representations before reaching L4. Their common outcome depends on the specified trimming rule.

Use such distinctions purposefully. Do not label every newly chosen value a new class merely to make a coverage report look more extensive.

Keep rules tied to the interface under test

A form text field may send every entered value as a string, while a direct request can contain booleans or arrays. The relevant input domains are different.

Inspect serialization, normalization, and schema checks before interpreting a result. A client-side rejection does not demonstrate that the service enforces the same requirement, and a service-level type case does not prove how the form presents an error.

The Form Testing Checklist covers the surrounding controls, messages, and submission behavior. Keep their observations separate from the class evidence collected at the declared service boundary.

Combine EP with other test design questions

Once the classes are defined, add tests for risks that class representatives leave open. Ordered limits need boundary-focused checks. Interacting conditions need deliberate combinations. Workflows whose behavior depends on prior events need sequences and known starting states.

For the booking example, an ordinary N3 value of 16 does not reveal a tier-change error specifically at 10. For the export example, three individually represented formats do not establish that every delivery pairing works. The appropriate addition depends on the untested rule.

Keep those additions traceable to their purpose. A test can contribute to several coverage measures, but the measures should not be merged into an undefined overall percentage. Full partition coverage remains a statement about the declared partition inventory.

Reusable equivalence partitioning test case template

Record these fields for each selected representative:

  • Requirement and scope: The behavior, input domain, interface, and conditions assumed valid before classification.
  • Partition set and class ID: The membership predicate and the distinct handling expected for that class.
  • Representative: The exact value, type, presence state, and any relevant normalized form.
  • Valid baseline: Other fields, permissions, source data, and expected initial effect counts.
  • Action: The request or interaction that causes the selected rule to be evaluated.
  • Expected result: Acceptance, error, output selection, saved values, and required or forbidden business effects.
  • Evidence and coverage: What was observed, which class was reached, and any masking or untested scope.

For request construction and response evidence, use the API Test Cases Checklist. A representative value plus a class label is useful test data; adding reproducible setup, action, and an independent expectation makes it an executable case.

Practical equivalence partitioning checklist

  • State the input domain and observation before grouping values.
  • Derive each class from an acceptance, rejection, transformation, or routing rule.
  • Define membership precisely enough to classify a new representative.
  • Check that every class is nonempty and that classes in one set do not overlap.
  • Check the domain for values that belong to no class.
  • Distinguish missing properties, nulls, empty values, and wrong types according to the contract.
  • Specify normalization and validation precedence before selecting ambiguous inputs.
  • Include valid alternatives and relevant invalid classes in the inventory.
  • Isolate invalid fields so unrelated failures do not mask the target rule.
  • Verify actual output and saved effects rather than only a success or error indicator.
  • Report Each Choice and combination coverage separately for multiple fields.
  • Record boundaries, interactions, history, and excluded domains as remaining test-design work.

Common mistakes

  • Grouping everything into valid and invalid. Distinct supported renderers or different validation outcomes can disappear inside groups that are too coarse for the test objective.
  • Writing overlapping membership rules. A value can be counted twice unless type, normalization, and validation precedence are defined consistently.
  • Ignoring the declared domain. An integer partition model is not evidence for how a request handles a missing number or a numeric-looking string.
  • Counting repetitions as new coverage. Several N2 representatives still exercise one class in the four-class numeric inventory.
  • Using multiple bad fields as independent negative evidence. A first-error response may conceal every later validation rule.
  • Treating accepted text as proof of correct processing. A successful JSON request that produces CSV content violates the format outcome despite passing acceptance.
  • Equating Each Choice with combination coverage. All classes can be represented while an important format-and-delivery pairing is absent.
  • Changing expected classes to follow a defect. Requirements should decide the expected grouping; a discovered implementation inconsistency needs investigation.

FAQ

In this testing context, equivalence classes are the groups used by equivalence partitioning. Define the membership rules and the partition set when reporting them so a label such as valid data has an explicit meaning and coverage scope.

They need distinct expectations when their required handling differs. The examples use accepted classes and rejected classes, with further splits where the outcome matters. The actual granularity should follow the test objective and requirements rather than a universal fixed number of groups.

Yes. A supported identifier such as json can form a singleton class when it selects a distinct processing outcome. The unsupported-format class can contain many values. Class sizes do not have to match, and each class must still have a meaningful membership rule.

Ready to turn this guide into a working QA project with statuses, comments, and CSV export?