草榴社区

Leveraging Equivalence Classes for Testing with TPT

Robert Fey

Jun 13, 2023 / 5 min read

102: Testing with Equivalence Classes

Introduction

In software testing, equivalence classes play a crucial role in efficiently validating the behavior of a system. These classes represent subsets of the possible value ranges of variables, such as inputs or outputs, where the system is expected to show similar behavior. By selecting representative values from these equivalence classes, we can systematically reduce the testing effort while still achieving significant coverage.  

In this blog post, we will explore the usage of equivalence classes in testing with (Time Partition Testing) and how they can optimize your testing process. 

Equivalence classes categorize values into distinct subsets, simplifying the testing process by selecting a representative value from each class.

For example, in our case, we have defined equivalence classes for light intensities as  

  • dark [0;60],  
  • bright [70;100] and 
  • twilight [60;70].

Similarly, switch positions are represented as  

  • off 0, 
  • on 1 and  
  • auto 2.  

The output signal, headlight off 0 and on 1, is also part of our example.

The Equivalence Class Test

The Equivalence Class Test aims to validate the system’s behavior by testing a few selected values from each equivalence class, thus saving considerable testing effort.  

Safety standards like ISO 26262 also require the application of equivalence class testing. Attempting to test “every” possible value within the value ranges would result in a significantly higher testing effort.  

While it may be feasible for integer numbers, the effort becomes immense for double precision. By systematically selecting one or more representatives from each equivalence class, the testing effort is reduced while maintaining measurable coverage.  

Additionally, a Cartesian product of equivalence classes can be considered, where each switch position is tested with all three light intensities. However, this approach can quickly increase the testing effort, especially when multiple inputs are involved. 

Assesslet

Image 1 showcases a coverage report in TPT that provides insights into the coverage achieved by the selected test cases for equivalence classes. It identifies the number of covered equivalence classes and indicates any remaining classes that require additional testing. 

Because it fits seamlessly into the discussion, let’s briefly introduce the importance of boundary value testing in software engineering.

Boundary Value Test

Equivalence class testing and boundary value testing are closely related in software testing. Equivalence class testing focuses on selecting representative values from different equivalence classes to reduce testing effort, while boundary value testing specifically targets the minimum and maximum values within those equivalence classes. 

Boundary value testing is important in software engineering for several reasons: 

  • Firstly, it helps uncover errors or issues that often occur at the boundaries of input or output ranges. These boundaries are typically where the behavior of the system changes, making them critical areas to test.  
  • Additionally, boundary value testing helps identify off-by-one errors, rounding errors, and other precision-related issues that can impact the correctness and reliability of the software. By thoroughly testing the boundaries, developers can ensure robustness and improve the overall quality of the software.

Just like any testing technique, equivalence classes have their own set of pros and cons. Here is a brief overview from a high-level perspective.

Advantages

1?? Systematic partitioning of input and output variables reduces testing effort. 

2?? Applicable to all testing stages, from unit tests to integration tests. 

Disadvantage

The creation of equivalence classes can be time-consuming and requires expertise based on requirements. 

Best Practice

1?? Create functional tests based on requirements and derive equivalence classes accordingly. 

2?? Execute the tests and verify the coverage. For any uncovered equivalence classes, create additional test cases. 

3?? Check if the behavior for those classes is specified or needs to be specified. 

Image 2: TPT Equivalence Class Management with TPT 

TPT provides a special equivalence class management function that allows users to conveniently create and manage equivalence classes. The function is divided into three dialogs: 

  • assignment of equivalence classes to signals (top left) 
  • definition of equivalence classes (top right) 
  • evaluation rules of equivalence classes for a test run (bottom)

As a result, the coverage report provides valuable insight into the completeness of your testing efforts by showing the equivalence classes covered and any remaining classes that require attention. 

For increased flexibility, you can specify the value range of an equivalence class using numerical values or parameters. The parameters can be defined and managed centrally in the declaration editor. If the specific value of a parameter needs to be adjusted over time, such as shifting a threshold, it will be automatically reflected in the equivalence class. 

Additionally, TPT goes beyond manual test case creation by providing automated test case generation for equivalence classes and boundary values. Leveraging the power of TPT’s automation capabilities, you can save time and effort in test case development while ensuring thorough testing of your software variants. 

Image 3 Automated Test Case Generation: showcases the automation capabilities of TPT, where test cases are automatically generated based on the defined equivalence classes and boundary values. This automation feature streamlines the testing process, eliminates manual effort, and ensures comprehensive coverage of critical scenarios. 

The configuration dialog located in the top right corner of Image 3 displays the option to include the boundaries (left and right) during generation. As a result, you will have not only one representative for each equivalence class but three values per equivalence class (left boundary, representative, right boundary). 

In the lower window of Image 3, you can see that no numerical values are generated during the generation of equivalence classes. Instead, references to the equivalence classes are created. This approach ensures robustness against changes. When executing a test run, concrete numerical values are used, which are explicitly reported in the test report. 

By utilizing TPT’s Equivalence Class Management and automated test case generation, you can streamline your testing process, improve efficiency, and confidently validate the behavior of your software variants. 

Conclusion

Equivalence classes play a vital role in efficient software testing, allowing you to systematically partition variables and optimize testing efforts. TPT provides robust support for managing equivalence classes, verifying their coverage, and automating test case generation. 

Are you ready to leverage the power of equivalence classes and enhance your testing process? Try TPT and experience firsthand how it simplifies the management and testing of software variants.

Continue Reading