Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个基于 guice 的 java 测试。我想传递多个受JUnitParams. 但看起来我只能通过一个@RunWith。所以基本上我可以添加JUnitParamsRunner或GuiceTestRunner。出路是什么?
JUnitParams
@RunWith
JUnitParamsRunner
GuiceTestRunner
不,一个测试类不能有多个运行器 - 这是 JUnit 4 的限制。但是,您可以有一个运行器和多个Rules。Guice没有官方Rule的,但您可以找到一些第三方解决方案(例如,此处或此处)或编写您自己的解决方案。这样你就可以有一个带有注释的测试类,@RunWith(JUnitParamsRunner.class)并有一个@Rule设置 Guice 的字段。
Rule
@RunWith(JUnitParamsRunner.class)
@Rule