私はPythonでBDDを見ています。検証中の結果は失敗時に出力されないため、結果の検証は面倒です。
動作出力の比較:
AssertionError:
File "C:\Python27\lib\site-packages\behave\model.py", line 1456, in run
match.run(runner.context)
File "C:\Python27\lib\site-packages\behave\model.py", line 1903, in run
self.func(context, *args, **kwargs)
File "steps\EcuProperties.py", line 28, in step_impl
assert vin == context.driver.find_element_by_xpath("//table[@id='infoTable']/tbody/tr[4]/td[2]").text
SpecFlow+NUnit 出力へ:
Scenario: Verify VIN in Retrieve ECU properties -> Failed on thread #0
[ERROR] String lengths are both 16. Strings differ at index 15.
Expected: "ABCDEFGH12345679"
But was: "ABCDEFGH12345678"
--------------------------^
SpecFlow の出力を使用すると、失敗の原因をすばやく見つけることができます。エラー時に変数の内容を取得するには、それらを手動で文字列に入れる必要があります。
レタスのチュートリアルから:
assert world.number == expected, \
"Got %d" % world.number
if text not in context.response:
fail('%r not in %r' % (text, context.response))
これをPython unittestと比較します。
self.assertEqual('foo2'.upper(), 'FOO')
その結果:
Failure
Expected :'FOO2'
Actual :'FOO'
<Click to see difference>
Traceback (most recent call last):
File "test.py", line 6, in test_upper
self.assertEqual('foo2'.upper(), 'FOO')
AssertionError: 'FOO2' != 'FOO'
ただし、Python unittest のメソッドはTestCase
インスタンスの外では使用できません。
Behave または Lettuce に統合された Python unittest の優れた点をすべて取得する良い方法はありますか?