软件测试因果图用例,《软件测试工程师》 17 用例设计方法-因果图(示例代码)...
时间: 2023-11-15 08:09:09 浏览: 42
因果图是一种测试用例设计方法,它可以帮助测试人员识别软件系统中可能出现的各种情况,并生成相应的测试用例。
以下是一个因果图示例代码:
```java
public class Calculator {
private int result = 0;
public int add(int a, int b) {
result = a + b;
return result;
}
public int subtract(int a, int b) {
result = a - b;
return result;
}
public int multiply(int a, int b) {
result = a * b;
return result;
}
public int divide(int a, int b) {
if (b == 0) {
throw new IllegalArgumentException("Cannot divide by zero!");
}
result = a / b;
return result;
}
public int getResult() {
return result;
}
}
```
通过因果图分析,我们可以得到以下测试用例:
1. 当输入两个正整数时,计算器应该能够正确相加并返回结果。
2. 当输入两个负整数时,计算器应该能够正确相加并返回结果。
3. 当输入一个正整数和一个负整数时,计算器应该能够正确相加并返回结果。
4. 当输入两个正整数时,计算器应该能够正确相减并返回结果。
5. 当输入两个负整数时,计算器应该能够正确相减并返回结果。
6. 当输入一个正整数和一个负整数时,计算器应该能够正确相减并返回结果。
7. 当输入两个正整数时,计算器应该能够正确相乘并返回结果。
8. 当输入两个负整数时,计算器应该能够正确相乘并返回结果。
9. 当输入一个正整数和一个负整数时,计算器应该能够正确相乘并返回结果。
10. 当输入两个正整数时,计算器应该能够正确相除并返回结果。
11. 当输入两个负整数时,计算器应该能够正确相除并返回结果。
12. 当输入一个正整数和一个负整数时,计算器应该能够正确相除并返回结果。
13. 当输入一个整数和零时,计算器应该抛出 IllegalArgumentException 异常。
这些测试用例可以帮助测试人员验证计算器的各种功能,并确保其正常工作。
相关推荐
![application/msword](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)