开发者

Cucumber background vs. before hook

I'm trying to figure out a good practice approach of when I should use Background over a Before hook.

I've browsed around the we开发者_StackOverflow中文版b looking at other peoples blog post but there's so much over lap.

Any opinions when to use which, and perhaps more importantly, when definitely not to use one of them?


My take on differentiating between the two comes down to using the tests as communication. If the functionality that you're adding is necessary for anyone reading the plain language Scenarios and features, it should go in the Background section. If the functionality is simply part of the implementation of your test framework, it should go into a Before hook.

Keeping the scenarios and features clear is an important part of building good Cucumber tests.

I guess another mental check you could use would be to ask yourself if someone was testing your scenarios manually, would they need to do the functionality that you want to put in the Background/before hook. If they would, I'd put it in the Background section in the feature file. If they wouldn't, put it in the hook back in your code.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜