0-Switch and 1-Switch Coverage
In the ISTQB Advanced Level Test Analyst syllabus, 0-switch and 1-switch coverage are coverage criteria for state transition testing, a behavior-based technique that models a system as states, the events that trigger transitions between them, and the resulting actions. The term 'switch' comes from … In the ISTQB Advanced Level Test Analyst syllabus, 0-switch and 1-switch coverage are coverage criteria for state transition testing, a behavior-based technique that models a system as states, the events that trigger transitions between them, and the resulting actions. The term 'switch' comes from Chow's N-switch coverage, where N is the number of intermediate states visited between the first and last transitions in a sequence. A test basis for these criteria is usually a state transition diagram or table. 0-switch coverage, also called single-transition or valid-transition coverage, requires each valid transition in the model to be exercised at least once. A sequence of length one (N+1 = 1) is the unit being covered, so if a model has eight valid transitions, 100% 0-switch coverage is reached when all eight have been executed. This finds missing or incorrect individual transitions, wrong target states and faulty actions, but it may miss defects that only appear when transitions occur in a particular order. 1-switch coverage, also called transition-pair coverage, requires every valid sequence of two consecutive transitions to be exercised at least once. For example, if the model has transitions A to B and B to C, the pair A to B to C must be tested. To derive these pairs, the analyst examines each state, combines every incoming transition with every outgoing transition, and lists all resulting pairs. This uncovers defects caused by the system's history, such as incorrect data carried between states or improper state memory. Because the number of pairs grows rapidly, 1-switch coverage demands significantly more test cases. Coverage is hierarchical: 1-switch subsumes 0-switch, and higher N-switch levels give more thorough testing at increasing cost. Test Analysts choose the level based on risk, so safety-critical or highly stateful systems often justify 1-switch or higher, while lower-risk components may only need 0-switch. Invalid transitions should also be considered, typically through a state table, to verify that the system correctly rejects events not allowed in a given state.
0-Switch and 1-Switch Coverage in State Transition Testing (ISTQB CTAL-TA)
Overview
0-switch and 1-switch coverage are coverage criteria for state transition testing, a behavior-based test technique in the ISTQB Advanced Level Test Analyst (CTAL-TA) syllabus. They measure how thoroughly your tests exercise the transitions of a state model. 0-switch looks at single transitions. 1-switch looks at pairs of consecutive transitions. Exam questions usually ask you to count coverage items, calculate a coverage percentage or design a minimal set of test cases.
1. Why It Is Important
Many systems behave differently depending on their history, not just on the current input. Examples include ATMs, login and lockout logic, media players, order workflows, embedded controllers and protocol handlers.
- Defects hide in sequences. A transition may work alone but fail when it follows a particular earlier transition. For example, 'resume' may work after 'pause' from playback but fail after 'pause' from fast-forward. Single-transition testing cannot reveal this. 1-switch testing can.
- Coverage gives a measurable exit criterion. Coverage levels let the Test Analyst state objectively how thorough the state-based testing is, for example '100% 0-switch, 85% 1-switch'.
- Risk-based choice of rigor. 0-switch is a sensible baseline. 1-switch (or higher N-switch) is justified for high-risk, safety-critical or history-sensitive components.
- Exam relevance. The CTAL-TA exam expects you to apply (K3) state transition testing. That includes deriving test cases and calculating coverage.
2. What It Is: Key Concepts and Definitions
State: a condition in which the system waits for or responds to events.
Transition: a change from one state to another (or to the same state), triggered by an event and possibly restricted by a guard condition. A transition may produce an action.
Valid transition: a transition that the model allows.
Invalid transition: an event that occurs in a state where the model defines no transition for it.
N-switch coverage: introduced by Chow. A 'switch' is the point where one transition hands over to the next. N-switch coverage considers sequences of N+1 consecutive valid transitions.
0-switch coverage (also called valid transitions coverage or single transition coverage)
- Coverage items: every individual valid transition.
- Coverage = (number of valid transitions exercised / total number of valid transitions) x 100%.
- Coverage items: every valid sequence of two consecutive transitions.
- Coverage = (number of valid transition pairs exercised / total number of valid transition pairs) x 100%.
Related criteria (do not confuse them):
- All states coverage: every state is visited. This is the weakest criterion.
- Valid transitions coverage: this is the same as 0-switch coverage.
- All transitions coverage: every valid transition is exercised and every invalid transition is attempted. Invalid transitions should be tested one per test case, to avoid defect masking.
3. How It Works: Step by Step
Step 1. Build or read the model. Work from a state transition diagram or a state table. In a state table, every non-empty cell is a valid transition and every empty or 'invalid' cell is an invalid transition.
Step 2. Label all valid transitions. Give each one a label (T1, T2, ...). The number of labels is the number of 0-switch coverage items.
Step 3. Count the 1-switch items. For each state, multiply the number of incoming transitions by the number of outgoing transitions. Then add the results for all states.
Total 1-switch items = sum over all states of (incoming transitions x outgoing transitions).
Remember these special cases:
- A self-loop counts as both incoming and outgoing for its state, so it can pair with itself.
- The initial pseudo-transition from the start marker is usually not counted unless the question says otherwise.
- Final states have no outgoing transitions, so they contribute 0 pairs.
Step 4. Design test cases. Each test case is a path of valid transitions, normally starting in the initial state. Chain transitions so that each path covers as many uncovered items as possible.
Step 5. Calculate the coverage achieved. Count the distinct items covered by all test cases together and divide by the total.
4. Worked Example
A media player has three states: Idle (the initial state), Running and Paused. It has five valid transitions:
- T1: Idle -> Running (start)
- T2: Running -> Paused (pause)
- T3: Paused -> Running (resume)
- T4: Running -> Idle (stop)
- T5: Paused -> Idle (stop)
One test from Idle achieves 100% 0-switch coverage: T1, T2, T3, T4, T1, T2, T5. That is start, pause, resume, stop, start, pause, stop.
1-switch items, counted per state:
- Idle: incoming T4 and T5 (2), outgoing T1 (1). That gives 2 pairs: T4-T1 and T5-T1.
- Running: incoming T1 and T3 (2), outgoing T2 and T4 (2). That gives 4 pairs: T1-T2, T1-T4, T3-T2 and T3-T4.
- Paused: incoming T2 (1), outgoing T3 and T5 (2). That gives 2 pairs: T2-T3 and T2-T5.
- Total: 2 + 4 + 2 = 8 pairs.
One test case achieving 100% 1-switch coverage:
T1, T2, T5, T1, T4, T1, T2, T3, T2, T3, T4
The pairs it covers, in order, are T1-T2, T2-T5, T5-T1, T1-T4, T4-T1, T1-T2 (repeat), T2-T3, T3-T2, T2-T3 (repeat) and T3-T4. That is all 8 distinct pairs. Repeated pairs do not add coverage.
Partial coverage example:
The 0-switch test above (T1, T2, T3, T4, T1, T2, T5) covers these distinct pairs: T1-T2, T2-T3, T3-T4, T4-T1 and T2-T5. That is 5 of 8 pairs, so 62.5% 1-switch coverage, even though 0-switch coverage is 100%. This illustrates that 100% 0-switch coverage does not imply 100% 1-switch coverage.
5. Practical Considerations
- The number of items grows quickly as N increases. 1-switch can be several times larger than 0-switch, and 2-switch larger again. Choose N based on risk.
- Guard conditions may make some theoretical pairs infeasible. Infeasible items should be documented and excluded or justified.
- Tests normally start from the initial state, so reaching some pairs requires 'setup' transitions. These setup transitions also count toward coverage.
- Invalid transitions are a separate concern. They are covered by all transitions coverage, not by switch coverage.
Exam Tips: Answering Questions on 0-Switch and 1-Switch Coverage
- Tip 1. Know the definitions cold. 0-switch means single valid transitions, and it equals valid transitions coverage. 1-switch means pairs of consecutive valid transitions. N-switch means sequences of N+1 transitions.
- Tip 2. Count transitions, not events or states. Label every arrow in the diagram, or every non-empty cell in the state table. Two arrows with the same event name but different source states are different transitions.
- Tip 3. Use the in x out formula for 1-switch. For each state, multiply incoming by outgoing, then add the results. This is faster and less error-prone than listing pairs by hand. Then list the pairs if the question needs specific sequences.
- Tip 4. Watch for self-loops. A self-loop on state S counts in both the incoming and outgoing totals of S, so it pairs with itself and with every other transition into or out of S.
- Tip 5. Ignore invalid transitions in switch coverage. If an option includes invalid transitions in a 0-switch or 1-switch count, it is a distractor. Invalid transitions belong to all transitions coverage.
- Tip 6. Count distinct items only. When calculating the coverage of a test set, merge the pairs from all test cases and remove duplicates before dividing.
- Tip 7. Check that test paths are continuous. In 'which test achieves...' questions, check that each transition starts in the state where the previous one ended, and that the path starts in the initial state if required. A broken path is an invalid test.
- Tip 8. Minimum test case questions. Prefer long chained paths. If the model has a final state, every test must end there, which may force additional test cases. Consider which states can be re-entered.
- Tip 9. Apply subsumption logic. 100% 1-switch generally implies 100% 0-switch. The reverse is not true. Also, 100% 0-switch does not guarantee that invalid transitions are tested.
- Tip 10. Read the stem carefully. Check whether it asks for coverage items, test cases or a percentage. Check whether the initial transition counts and whether test cases must begin in the start state. Small wording differences change the answer.
- Tip 11. Write it out. On scratch paper, draw a quick table with columns for State, In, Out and In x Out. It takes about 30 seconds and prevents most counting mistakes.
- Tip 12. Eliminate distractors with sanity checks. The 1-switch total is usually larger than the 0-switch total. An answer that gives fewer 1-switch items than transitions is suspicious unless the model has many final or dead-end states.
Summary
0-switch coverage ensures every valid transition is exercised once. 1-switch coverage ensures every valid pair of consecutive transitions is exercised, which exposes history-dependent defects. In the exam:
- Label the transitions.
- Count 0-switch items directly.
- Count 1-switch items using the sum of in x out per state.
- Verify that test paths are continuous.
- Count only distinct, valid items when calculating coverage percentages.
Unlock Premium Access
ISTQB Certified Tester Advanced Level Test Analyst
- Access to ALL Certifications: Study for any certification on our platform with one subscription
- 3161 Superior-grade ISTQB Certified Tester Advanced Level Test Analyst practice questions
- Unlimited practice tests across all certifications
- Detailed explanations for every question
- CTAL-TA: 5 full exams plus all other certification exams
- 30-Day Money-Back Guarantee: Full refund within 30 days if unsatisfied
- Risk-Free: 7-day free trial with all premium features!