我使用 Assert。在进行 TDD 时经常会失败。我通常一次只处理一个测试,但是当我得到想要实现的东西时,我会迅速编写一个空的测试,其中测试方法的名称表明我想要实现的东西作为一种待办事项列表。为了确保我不会忘记。身体不适。
当试用 xUnit 时。我发现他们没有实现 Assert。失败。当然你可以一直断言 Assert.IsTrue (false) ,但是这并不能表达我的意图。我觉得 Assert。失败不是故意实现的。这算是坏习惯吗?如果是这样,为什么?
@ Martin Meredith 我可不是这么做的。我首先编写一个测试,然后实现代码使其工作。通常我会同时考虑几个测试。或者当我在做其他事情的时候,我会考虑写一个测试。这时我写了一个空的失败测试来记住。当我开始写测试的时候,我整洁地先写测试。
@ Jimmeh 看起来是个好主意。被忽略的测试不会失败,但是它们仍然显示在一个单独的列表中。我得试试。
@ Matt Howells 伟大的想法。异常比断言更好地传达意图。在这种情况下,Fail ()
@ 米奇・维特 这就是我要找的。似乎是为了防止它被另一种方式滥用,我滥用它。