nimoy-framework
ASTに介入してUnitTestコードを分かりやすく書けるフレームワーク
> The Spock Framework has set a new standard as to what testing frameworks should be like - beautiful, expressive, pragmatic and fun.
pythonfrom 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
test.pyclass SomeTest:
@pytest.mark.parametrize(
"value_of_a,value_of_b,expected_value",
[
(1, 10, 10),
(2, 20, 40),
]
)
def test_my_feature(self, value_of_a, value_of_b, expected_value):
# Arrange
a = value_of_a
b = value_of_b
# Act & Assert
assert (a * b) == expected_value
3a3A Pattern | pytest | nimoy |
Arrange (準備) | テスト関数内 | given |
Act(実行) | テスト関数内 | expect |
Assert (判定) | テスト関数内 | expect |
パラメータ | parametrize | where |
んー、もしかしたらActはgivenでやってもいいのかな
examplesを見ると setup
, when
, then
というのもある...なるほど?
setup
, expect
で使ってる例もあるな。。
結局 setup
, when
, then
, given
, expect
, where
の使い方の定義はないのかな?
このへんがドキュメントに書いてないので使おうという気になれない