TDD.什么时候可以继续? [英] TDD. When you can move on?

查看:25
本文介绍了TDD.什么时候可以继续?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在执行 TDD 时,如何判断对此类/功能进行了足够的测试"?

When doing TDD, how to tell "that's enough tests for this class / feature"?

即你什么时候能说你完成了所有边缘情况的测试?

I.e. when could you tell that you completed testing all edge cases?

推荐答案

使用测试驱动开发,您将在编写测试代码之前先编写测试.一旦您编写了代码并且测试通过了,那么就该编写另一个测试了.如果您正确地遵循 TDD,那么一旦您的代码完成了所有需要的工作,您就已经编写了足够多的测试.

With Test Driven Development, you’ll write a test before you write the code it tests. Once you’re written the code and the test passes, then it’s time to write another test. If you follow TDD correctly, you’ve written enough tests once you’re code does all that is required.

对于边缘情况,让我们举一个例子,比如验证方法中的参数.在将参数添加到代码之前,您需要创建测试以验证代码将正确处理每种情况.然后您可以添加参数和关联逻辑,并确保测试通过.如果您想出更多边缘情况,则可以添加更多测试.

As for edge cases, let's take an example such as validating a parameter in a method. Before you add the parameter to you code, you create tests which verify the code will handle each case correctly. Then you can add the parameter and associated logic, and ensure the tests pass. If you think up more edge cases, then more tests can be added.

通过一次一个步骤,您在编写完代码后就不必担心边缘情况,因为您已经为它们编写了所有测试.当然,总会有人为错误,你可能会遗漏一些东西......当这种情况发生时,是时候添加另一个测试然后修复代码了.

By taking it one step at a time, you won't have to worry about edge cases when you've finished writing your code, because you'll have already written the tests for them all. Of course, there's always human error, and you may miss something... When that situation occurs, it's time to add another test and then fix the code.

这篇关于TDD.什么时候可以继续?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆