官术网_书友最值得收藏!

What is a good test?

When we are writing tests, we need to keep in mind a series of guidelines in order to end up with a useful test suite. Every test we write should have the following properties:

  • They should be relevant. A test must be relevant from the point of view of the product. There is no point in testing something that, when it is done, does not clearly move the project forward to completion. This is automatically achieved by BDD, but not by traditional TDD.
  • They should be repeatable. Tests must always offer the same results if there has not been a code change. If it is failing, you must change the code to see it pass, and if it is passing, it must not start failing if nobody changed the code. This is achieved through a correct setup of the system and the use of test doubles. If tests are not repeatable, they offer no useful information! I have seen teams ignore tests that are flipping between passing and failing because of incorrect setup or race conditions. It would have been better not to waste time and money in writing a test that nobody cares about because it is not reliable.
  • They should be fast. After all, one key point of test-first is rapid feedback and quick iteration. It is not very cost effective if you need to wait 15 minutes for the tests to end whenever you make a code change in a test-first cycle.
  • They should be isolated. A test should fail only because the feature (or component) it is testing has a defect. This will help us diagnose the system to pinpoint where the error is. This will help us write code in an incremental fashion in the order our customers require (often, the most valuable features first). If the test is not isolated, then we often cannot write a new test, because we need first to write another feature or component that this one depends on.
主站蜘蛛池模板: 洱源县| 广昌县| 津市市| 班戈县| 乌鲁木齐县| 调兵山市| 大港区| 平武县| 远安县| 岳西县| 泽库县| 海门市| 石门县| 黎平县| 瑞安市| 衢州市| 荔浦县| 贡觉县| 湘阴县| 安仁县| 临颍县| 新兴县| 定安县| 边坝县| 罗江县| 淄博市| 泰安市| 新民市| 苍南县| 香河县| 鹤壁市| 尖扎县| 佛冈县| 桓台县| 囊谦县| 施秉县| 长武县| 石屏县| 祁阳县| 福鼎市| 独山县|