说我有一个播放全局文件......
public class Global extends GlobalSettings {
private ApplicationContext ctx;
@Override
public void onStart(Application app) {
ctx = new ClassPathXmlApplicationContext("context/components.xml");
}
@Override
public <A> A getControllerInstance(Class<A> clazz) {
return ctx.getBean(clazz);
}
}
我有这样的测试...
@Test
public void itShouldFailOnMissingFields() throws Exception {
running(fakeApplication(), () -> {
Map<String, String> body = new HashMap<String, String>();
body.put("email", "jason@goodwin.com");
body.put("password", "ro");
FakeRequest request = new FakeRequest(POST, "/v1/profile")
.withFormUrlEncodedBody(body);
Result result = route(request);
assertEquals(status(result), 400);
}
);
}
如何将测试依赖项注入控制器?我还有其他方法可以测试吗?
答案 0 :(得分:0)