就在这里!
我是Nimoy的作者——一个为 Python 构建的框架。
您可以创建数据驱动的测试:
from nimoy.specification import Specification
class MySpec(Specification):
def my_feature_method(self):
with given:
a = value_of_a
b = value_of_b
with expect:
(a * b) == expected_value
with where:
value_of_a | value_of_b | expected_value
1 | 10 | 10
2 | 20 | 40
您可以进行模拟:
from unittest import mock
from nimoy.specification import Specification
class MySpec(Specification):
def my_feature_method(self):
with setup:
the_mock = mock.Mock()
with when:
the_mock.some_method() << [5, 6, 7]
with then:
the_mock.some_method() == 5
the_mock.some_method() == 6
the_mock.some_method() == 7
我们也有非常模拟的断言:
from unittest import mock
from nimoy.specification import Specification
class MySpec(Specification):
def my_feature_method(self):
with setup:
the_mock = mock.Mock()
with when:
the_mock.some_method('abcd', True)
with then:
1 * the_mock.some_method('abcd', True)