eos测试规格
by Edd Yerburgh
埃德·耶堡(Edd Yerburgh)
希望您的测试更有效? 这样写您的规格。 (Want your tests to be more effective? Write your specifications like this.)
Writing test specifications is tricky. If you get it right, your tests are easy to understand and debug. But get it wrong, and your tests will be confuse people more than they’ll help them.
编写测试规范非常棘手。 如果您做对了,您的测试很容易理解和调试。 但是弄错了,您的测试会使人们更加困惑,而不是帮助他们。
In this article, I’ll show you how to write expressive test specifications.
在本文中,我将向您展示如何编写表达性测试规范。
什么是测试规格? (What are test specifications?)
Test specifications (specs) are the string used to identify tests when they’re run by a test runner.
测试规范(specs)是由测试运行程序运行时用于标识测试的字符串。
Below you can see an example of the output from a failed test. You can see where the specification and assertion error is used to describe how a test failed.
在下面,您可以看到测试失败的输出示例。 您可以看到规范和断言错误用于描述测试失败的位置。
为什么测试规格很重要? (Why are test specifications important?)
When a test fails, the way you identify it is with the test specification.
如果测试失败,则可以通过测试规范来识别它。
If the specification is well-written, you’ll know straight away why the test failed by using the test specification and the test assertion.
如果规范写得好,您将通过使用测试规范和测试断言直接了解为什么测试失败。
calls showModal when button is clickedError: Expected spy to have been called but it was not.
We can guess that the test failed because showModal wasn’t called when the button was clicked. This debugability is what you should aim for in tests.
我们可以猜测测试失败,因为单击按钮时未调用showModal。 这种可调试性是您在测试中应该追求的目标。
Lets look at som