我最近将Guice引入了我的ActionBeans,此前ActionBean的数据访问层实现了硬编码。

我有这样的集成测试:

MockServletContext context = TestHelper.getServletContext();
MockRoundtrip trip = new MockRoundtrip(context, LoginActionBean.class);


trip.setParameter("authenticate", "Login");
trip.setParameter("username", "testuser2");
trip.setParameter("password", "testuser2pass");
trip.setParameter("targetUrl", "Activity.action?jobId=1");
trip.execute();

LoginActionBean bean = trip.getActionBean(LoginActionBean.class);

现在我正在使用GUICE,我无法找到一种将依赖项注入登录方式的方法,因为我从来没有自己实际实例化。

我该如何告诉Guice将依赖项注入此类?

有帮助吗?

解决方案

您将需要配置 MockServleTContext 具有GUICE配置,就像您在Web.xml中一样(可能在您的 TestHelper 班级 getservletContext() 方法)。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top