我一直在努力使这个测试工作:
@RunWith(Arquillian.class)
@RunAsClient
public class AnnotatedEchoServletTestCase {
@Deployment(testable = false)
public static WebArchive getTestArchive() {
return ShrinkWrap.create(WebArchive.class, "servlet-test.war").addClass(EchoServlet.class);
}
@ArquillianResource
URL deploymentUrl;
@Test
public void shouldBeAbleToInvokeServletInDeployedWebApp() throws Exception {
String requestUrl = deploymentUrl + EchoServlet.URL_PATTERN.substring(1) + "?" + EchoServlet.MESSAGE_PARAM + "=hello";
String body = StreamReaderUtil.readAllAndClose(new URL(requestUrl).openStream());
Assert.assertEquals("Verify that the servlet was deployed and returns expected result", "hello", body);
}
}
但是,我收到此错误:
Provider for type class java.net.URL returned a null value
如果我@ArquillianResource URL
从代码中删除,测试通过而没有错误。
如果我有这个 arquillian.xml,可能会缺少什么:
<?xml version="1.0" encoding="UTF-8"?>
<arquillian xmlns="http://jboss.org/schema/arquillian"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://jboss.org/schema/arquillian
http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
<container qualifier="jbossas-managed" default="true">
<configuration>
<!-- If you want to use an existing JBoss AS installation, change the value of this property to that path -->
<!-- If you've already set the JBOSS_HOME environment variable, you can remove this configuration block -->
<property name="jbossHome">target/jboss-as-7.1.1.Final</property>
<property name="outputToConsole">true</property>
</configuration>
</container>
</arquillian>