我试图了解TDD方法并且遇到 – 我认为是 – 鸡和鸡蛋问题:如果错误修复涉及更改方法的签名该怎么办.
请考虑以下方法签名:
string RemoveTokenFromString (string delimited,string token)
顾名思义,此方法从分隔中删除令牌的所有实例,并返回结果字符串.
我后来发现这个方法有一个错误(例如,从字符串中删除了错误的位).因此,我编写了一个测试用例,描述了发生错误的场景,并确保测试失败.
修复错误时,我发现该方法需要更多信息才能正常工作 – 这些信息只能作为参数发送(被测方法是静态类的一部分).
那我该怎么办?如果我修复了这个bug,这迫使我改变单元测试 – 这是’正确的’TDD方法吗?
当您发现设备的预期行为发生变化时,对您的测试进行轰炸绝对没有错.
原文链接:https://www.f2er.com/javaschema/281594.html//Up front [Test] public void should_remove_correct_token_from_string() { var text = "do.it.correctly.."; var expected = "doitcorrectly"; Assert.AreEqual(StaticClass.RemoveTokenFromString(text,"."),expected); } //After finding that it doesn't do the right thing //Delete the old test and *design* a new function that //Does what you want through a new test //Remember TDD is about design,not testing! [Test] public void should_remove_correct_token_from_string() { var text = "do.it.correctly.."; var expected = "doitcorrectly"; Assert.AreEqual( StaticClass.RemoveTokenFromString( text,".",System.Text.Encoding.UTF8),expected); } //This will force you to add a new parameter to your function //ObvIoUsly now,there are edge cases to deal with your new parameter etc. //So more test are required to further design your new function