开发者

are scenarios/stories the new interface in BDD/TDD?

PHP is somewhat crippled since it doesn't have return types (yet). I need my code to throw an exception when X already exists. I can write this in a scenario, but I'm not able to go from the scenarios to the interface my class should implement.

Actually this problem is the same in TDD I guess. There seems more that I can tell through my 't开发者_运维问答ests' than through my interfaces. Yet my interfaces define what components can interact, what responsibilities they should take.

The problem is bigger in PHP because it doesn't have return types but it also exists in other languages because there is no contract that says an exception should be thrown when x is the case.

How can I best deal with this?


In languages that throw exceptions, the interface is only part of the contract specification. Use the tests to describe the rest of the contract by asserting that the correct exceptions are thrown when expected.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜