Equivalence classes are a set of input values that produce the same result.
It’s important to know the equivalence classes for your system under test, because you can use equivalence classes to limit your test cases.
Let’s look at an example. Let’s say you have a user interface that looks like this:
Enter a number from 1 to 10: ___
Remember, we’re only talking about automated regression testing, not all testing. For example, you might want to try “A”, or “<space>”. Those are great exploratory tests, but you aren’t likely to automate them.
Once you do some exploratory testing you determine that the developer has used a numeric control that won’t accept any character except 0 to 9. You automation isn’t going to test the underlying control that the developer didn’t write. Instead consider what values you might use in an automated test.
Equivalence classes tell us we don’t have to try every possible integer. What are the three ranges that produce similar results?
The valid range is 1 ≤ number ≤ 10, so you have values that are:
- Too low
- In range
- Too high
You can see we can use data-driven testing to solve this. Here’s the table with 3 tests:
APIs especially lend themselves to data-driven testing using equivalence classes and data-driven testing.
Boundary value analysis
Boundary value analysis extends equivalence classes to say: “A lot of calculation problems happen on the boundary values. Let’s make sure we test those.”
In the example above, we see that the boundaries are on 1 and 10. In boundary value analysis, we pick test values on each boundary and on both sides of the boundary. That’s really all there is to the analysis.
So, in this example we have:
So, the test values are: 0, 1, 2, 9, 10 and 11. We keep the values 1, 2, 9 and 10, even though they are in the same equivalence class and should do the same thing, because they are on a boundary and more likely to cause a problem in a calculation.
Boundary value analysis will lead to more tests than equivalence classes will, so you want to use it for situations where you are doing a calculation based on the data and the boundary might cause a problem if not handled correctly.
Just like with equivalence classes, you can use data-driven testing to automate boundary values.
The next article in the test technique series is on using a test oracle to reduce the number of tests we need to write.
Copyright © 2019, All Rights Reserved by Bill Hodghead, shared under creative commons license 4.0