Do not rely only on comments to provide information about test objectives. Comments do not appear when tests are executed from your favorite IDE, nor do they appear in reports generated by the CI or build tools.
不要仅仅依靠注释来提供有关测试目标的信息。 从您喜欢的 IDE 执行测试时不会出现注释,也不会出现在 CI 或构建工具生成的报告中。
除了编写测试,您还需要运行它们。由于我们使用的是 Gradle,因此可以从命令提示符下运行它们:
...
...
@@ -240,7 +240,7 @@ public class TicTacToeSpec {
}
```
When a piece is placed anywhere outside the *x*-axis, then `RuntimeException` is thrown.
Write the test before writing the implementation code .
在编写实现代码之前编写测试。
The benefits of doing this are as follows—it ensures that testable code is written and ensures that every line of code gets tests written for it.
这样做的好处如下——它确保编写了可测试的代码,并确保每一行代码都为它编写了测试。
By writing or modifying the test first, the developer is focused on requirements before starting to work on a code. This is the main difference when compared to writing tests after the implementation is done. An additional benefit is that with tests first, we are avoiding the danger that the tests work as quality checking instead of quality assurance.