【发布时间】:2016-04-04 10:42:46
【问题描述】:
我正在尝试寻找一种可移植的解决方案来测试我的 Java EE 7 应用程序。测试 EJB 及其注入时尤其棘手。例如:
@org.junit.Test
public void testIsValidCredentials() throws Exception {
System.out.println("isValidCredentials");
String username = "";
String password = "";
Map properties = new HashMap();
properties.put(EJBContainer.MODULES, new File[] {new File("target/classes")});
EJBContainer container = javax.ejb.embeddable.EJBContainer.createEJBContainer();
AuthenticatorLocal instance = (AuthenticatorLocal) container.getContext().lookup("java:global/classes/Authenticator");
boolean expResult = false;
boolean result = instance.isValidCredentials(username, password);
assertEquals(expResult, result);
container.close();
}
当我运行测试时,我会得到:
没有可用的 EJBContainer 提供程序
我也尝试使用选项properties.put(EJBContainer.PROVIDER, ""),但没有成功。 Glassfish 有一些可用的文档,但对于 Wildfly,它真的很差。
我也听说过 arquillian,但我只看到 Alpha 包,这似乎对生产不安全。有谁知道用于(集成)测试的便携式解决方案?
【问题讨论】:
-
你考虑过Arquillian吗?
标签: jakarta-ee junit wildfly java-ee-7 glassfish-4.1