根据计算器的加法计算场景 编写pytest自动化测试用例
时间: 2023-07-05 09:04:52 浏览: 69
可以根据以下场景编写pytest自动化测试用例:
1. 测试两个正整数相加的结果是否正确;
2. 测试两个负整数相加的结果是否正确;
3. 测试一个正整数和一个负整数相加的结果是否正确;
4. 测试两个小数相加的结果是否正确;
5. 测试一个整数和一个小数相加的结果是否正确;
6. 测试两个大数相加的结果是否正确;
7. 测试输入非数字字符时是否会抛出异常;
8. 测试输入为空时是否会抛出异常;
9. 测试输入超过两个数字时是否会抛出异常;
10. 测试输入为科学计数法时是否会正确计算。
以下是一个示例的pytest自动化测试用例:
```python
import pytest
from calculator import add
def test_add_positive_numbers():
assert add(2, 3) == 5
def test_add_negative_numbers():
assert add(-2, -3) == -5
def test_add_positive_and_negative_numbers():
assert add(2, -3) == -1
def test_add_decimal_numbers():
assert add(2.5, 3.7) == 6.2
def test_add_integer_and_decimal_numbers():
assert add(2, 3.7) == 5.7
def test_add_large_numbers():
assert add(99999999999999999999999999999999999999999999999999999999999, 1) == 100000000000000000000000000000000000000000000000000000000000
def test_add_non_numeric_input():
with pytest.raises(TypeError):
add("2", "3")
def test_add_empty_input():
with pytest.raises(ValueError):
add("", "")
def test_add_more_than_two_numbers():
with pytest.raises(ValueError):
add(1, 2, 3)
def test_add_scientific_notation_numbers():
assert add(1e5, 2e-3) == 100.002
```