事实证明,JUnit 想要@BeforeClass
并且是静态的,这与 JerseyTest 的方法覆盖@AfterClass
不符。configure
是否有一种已知的方法来配置 Jersey 应用程序,同时仍然能够访问 JUnit 的实用程序方法?
public class MyControllerTest extends JerseyTest {
@BeforeClass
public static void setup() throws Exception {
target("myRoute").request().post(Entity.json("{}"));
}
@Override
protected Application configure() {
return new AppConfiguration();
}
}
因此beforeClass
需要是静态的,target
因为它的实例方法性质而不能被调用。在尝试使用构造函数时,事实证明它configure
在之后运行constructor
,这会阻止执行设置请求,因此自然会失败。
任何建议都非常感谢,谢谢!