按合同设计为您工作吗? [英] Does Design By Contract Work For You?
问题描述
我遇到了按合同设计方法在研究生课程中。在学术界,似乎是一个非常有用的技术。但是我目前没有使用专业的按合同设计,而且我不知道任何其他正在使用它的开发人员。从SO人群中了解其实际使用情况可能会很好。
我不能非常推荐它。如果您有一套套件,可以采用内联文档合同规范,如下所示:
// @returns null iff x = 0
public foo(int x){
...
}
并将其转换为生成的单元测试,如下所示:
public test_foo_returns_null_iff_x_equals_0(){
assertNull foo 0);
}
这样,你可以看到你正在运行的测试,但是自动生成生成的测试不应该被检查到源代码控制,顺便说一句。
Do you use Design by Contract professionally? Is it something you have to do from the beginning of a project, or can you change gears and start to incorporate it into your software development lifecycle? What have you found to be the pros/cons of the design approach?
I came across the Design by Contract approach in a grad school course. In the academic setting, it seemed to be a pretty useful technique. But I don't currently use Design by Contract professionally, and I don't know any other developers that are using it. It would be good to hear about its actual usage from the SO crowd.
I can't recommend it highly enough. It's particularly nice if you have a suite that takes inline documentation contract specifications, like so:
// @returns null iff x = 0
public foo(int x) {
...
}
and turns them into generated unit tests, like so:
public test_foo_returns_null_iff_x_equals_0() {
assertNull foo(0);
}
That way, you can actually see the tests you're running, but they're auto-generated. Generated tests shouldn't be checked into source control, by the way.
这篇关于按合同设计为您工作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!