我在 eclipse 上使用 cucumber 和 maven,我想做的是独立运行每个测试。例如,我有一个图书馆系统软件,基本上允许用户借书和做其他事情。
其中一个条件是用户最多只能借两本书,所以我写信来确保该功能有效。这是我的功能文件:
Scenario: Borrow over max limit
Given "jim@help.ca" logs in to the library system
When "jim@help.ca" order his first book with ISBN "9781611687910"
And "jim@help.ca" orders another book with ISBN "9781442667181"
And "jim@help.ca" tries to order another book with ISBN "1234567890123"
Then jim will get the message that says "The User has reached his/her max number of books"
我写了一个相应的步骤定义文件,每一个都很好。但是,将来我想使用相同的用户名(“jim@help.ca”)来借书,就好像 jim@help.ca 还没有借过任何书一样。我希望每个测试都相互独立。
有什么方法可以做到这一点...也许我可以将一些东西放入我的步骤定义类中,例如拆卸方法。我已经调查过了,但我找不到任何关于它的可靠信息。如果有办法请帮助我。非常感谢任何帮助,我提前感谢您!
最佳答案
是的,您可以在每个场景前后进行设置和拆卸,但它不在步骤定义文件中。您要使用的是钩子(Hook)。
Hook 在场景之前或之后运行,并且可以在每个场景之前/之后运行,或者仅在您和@tag 到的场景之前/之后运行,例如:
@remove_borrowed_books
Scenario: Borrow over max limit
不幸的是,我只将 Cucumber 与 ruby 而非 java 一起使用,所以我无法为您提供分步说明,但这应该会告诉您您需要了解的内容 https://zsoltfabok.com/blog/2012/09/cucumber-jvm-hooks/
关于java - 独立运行每个 cucumber 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46967015/