This tutorial aims to introduce you to the basics of Cause-Effect Graphing, a structured and systematic approach to generating test cases. It's a black-box testing technique used in system testing and integration testing.
Cause-Effect Graphing is a testing technique that visualizes the relationship between different conditions (causes) and their outcomes (effects). The graph is a directed graph with nodes representing causes and effects, and the edges represent the relations between them.
Creating a cause-effect graph involves the following steps:
A decision table is a good way to deal with different combination inputs with their associated outputs for a given system. It's a structured exercise to prepare test cases from a complex nested if-else condition.
The final step is to generate the test cases. Each path from cause to effect in the graph represents a potential test case.
Since cause-effect graphing is a testing technique, it is more about design and does not directly involve coding. However, understanding how test cases derived from cause-effect graphing would look in code can be beneficial.
# Let's consider a simple login system with two causes: 'valid_username' and 'valid_password'.
# The effect is 'access_granted'.
# Test Case 1: Both username and password are valid
valid_username = True
valid_password = True
if valid_username and valid_password:
access_granted = True
else:
access_granted = False
print(access_granted) # Expected output is True (access is granted)
# Test Case 2: Username is valid, but password is not
valid_username = True
valid_password = False
if valid_username and valid_password:
access_granted = True
else:
access_granted = False
print(access_granted) # Expected output is False (access is not granted)
In this tutorial, we've covered the basics of cause-effect graphing, how to create a cause-effect graph, how to translate it into a decision table, and how to generate test cases from it. We also went through a simple example of how test cases derived from cause-effect graphing would look in code.
Create a cause-effect graph for a system that takes three inputs: a, b, and c. The system outputs True if at least two inputs are True. Generate all possible test cases.
Create a cause-effect graph for a system that takes a number as input. The system outputs 'positive' if the number is greater than 0, 'negative' if the number is less than 0, and 'zero' if the number is 0. Generate all possible test cases.
For further practice, try to create cause-effect graphs and generate test cases for more complex systems.