考虑您有以下方法:
public Foo ParseMe(string filepath)
{
// break up filename
// validate filename & extension
// retrieve info from file if it's a certain type
// some other general things you could do, etc
var myInfo = GetFooInfo(filename);
// create new object based on this data returned AND data in this method
}
目前我有单元测试GetFooInfo
,但我认为我还需要为ParseMe
. 在这种情况下,您有两个方法返回两个不同的属性 - 并且其中任何一个的更改都可能破坏某些东西 - 是否应该为两者创建单元测试以确定输出是否符合预期?
我喜欢在谨慎方面犯错,并且对发生故障的事情更加警惕,并确保以后的维护更容易,但我对在测试项目中添加非常相似的测试持怀疑态度。这是不好的做法还是有什么方法可以更有效地做到这一点?
我将此标记为与语言无关,但以防万一我使用 C# 和 NUnit - 另外,我只在标题中看到了与此类似的帖子,但问题有所不同。对不起,如果这已经被问到了。