Test Cases and Scenarios - Equivalence Class
Equivalence Class* Equivalence class testing is a technique used to reduce the number of test cases to a manageable level while still maintaining reasonable test coverage.* This simple technique is used intuitively by almost all testers, even though they may not be aware of it as a formal test design method. * Many testers have logically deduced its usefulness, while others have discovered it simply because of lack of time to test more thoroughly. Equivalence Class* Consider this situation. We are writing a module for a human resources system that decides how we should process employment applications based on a person's age. Our organization's rules are:Equivalence Class of Hire * 0-16 Don't hire * 16-18 Can hire on a part-time basis only * 18-55 Can hire as a full-time employee * 55-99 Don't hire[*] Equivalence Class of Hire* Should we test the module for the following ages: 0, 1, 2, 3, 4, 5, 6, 7, 8, ..., 90, 91, 92, 93, 94, 95, 96, 97, 98, 99?* If we had lots of time ? Develop coding * If (applicantAge == 0) hireStatus="NO"; * If (applicantAge == 1) hireStatus="NO"; * ... * If (applicantAge == 14) hireStatus="NO"; * If (applicantAge == 15) hireStatus="NO"; * If (applicantAge == 16) hireStatus="PART"; * If (applicantAge == 17) hireStatus="PART"; Develop coding * If (applicantAge == 18) hireStatus="FULL"; * If (applicantAge == 19) hireStatus="FULL"; * ... * If (applicantAge == 53) hireStatus="FULL"; * If (applicantAge == 54) hireStatus="FULL"; * If (applicantAge == 55) hireStatus="NO"; * If (applicantAge == 56) hireStatus="NO"; * ... * If (applicantAge == 98) hireStatus="NO"; * If (applicantAge == 99) hireStatus="NO"; Develop coding * Luckily, programmers don't write code like this (at least not very often). A better programmer might write: Develop coding If (applicantAge >= 0 && applicantAge <=16) hireStatus="NO"; If (applicantAge >= 16 && applicantAge <=18) hireStatus="PART"; If (applicantAge >= 18 && applicantAge <=55) hireStatus="FULL"; If (applicantAge >= 55 && applicantAge <=99) hireStatus="NO"; Equivalence Class* Given this typical implementation, it is clear that for the first requirement we don't have to test 0, 1, 2, ... 14, 15, and 16.* Only one value needs to be tested. * And which value? Any one within that range is just as good as any other one. * The same is true for each of the other ranges. * Ranges such as the ones described here are called equivalence classes. Equivalence ClassWe will expect:* If one test case in an equivalence class detects a defect, all other test cases in the same equivalence class are likely to detect the same defect. * If one test case in an equivalence class does not detect a defect, no other test cases in the same equivalence class is likely to detect the defect. Equivalence ClassA group of tests forms an equivalence class if you believe that:* They all test the same thing. * If one test catches a bug, the others probably will too. * If one test doesn't catch a bug, the others probably won't either Continuous equivalence classesDiscrete equivalence classesSingle selection equivalence classes* GMC will make mortgages only for a person. They will not make mortgages for corporations, trusts, partnerships, or any other type of legal entity. Multiple selection equivalence class * GMC will make mortgages on Condominiums, Townhouses, and Single Family dwellings. They will not make mortgages on Duplexes, Mobile Homes, Treehouses, or any other type of dwelling Identifying Equivalence Class* If an input condition specifies a continuous range of values, select one valid class and two invalid classes* If an input condition specifies a discrete range of permissible values, select one valid class and two invalid classes Identifying Equivalence Class * If an input condition enumerates a set of values, identify one valid equivalence class and one invalid equivalence class * If a 搈ust be?condition is required, identify one valid equivalence class and one invalid equivalence class Reference* A Practitioner's Guide to Software Test Designby Lee Copeland ISBN:158053791X Artech House ?2004 * Beizer, Boris (1990). Software Testing Techniques (Second Edition). Van Nostrand Reinhold. * Binder, Robert V. (2000). Testing Object-Oriented Systems: Models, Patterns, and Tools. Addison-Wesley. Choosing Test DataIn system testing, test data should cover the possible values of each parameter based on the the requirements. Since testing every value is impractical, a few values should be chosen from each equivalence class. An equivalence class is a set of values that should all be treated the same. Ideally, test cases that check error conditions are written separately from the functional test cases and should have steps to verify the error messages and logs. Realistically, if error test cases are not yet written, it is OK for testers to check for error conditions when performing normal functional test cases. It should be clear which test data, if any, is expected to trigger errors. Example equivalence classes:
|