我确实遇到了奇怪的错误。这是我的 Maven 部门:
<dependency>
<groupId>httpunit</groupId>
<artifactId>httpunit</artifactId>
<version>1.7</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>servlet-api</artifactId>
<groupId>javax.servlet</groupId>
</exclusion>
</exclusions>
</dependency>
这是我的 Java 基类:
static{
//trying to make it to work....
HttpUnitOptions.setScriptingEnabled(false);
HttpUnitOptions.setExceptionsThrownOnScriptError(false);
}
@BeforeMethod(groups = "integration")
public void setup() throws Exception {
//not working....
HttpUnitOptions.setScriptingEnabled(false);
HttpUnitOptions.setExceptionsThrownOnScriptError(false);
}
/**
* Sends request to servlet
* */
protected WebResponse sendPostRequest(String d, List<CookieBean> cookies) throws Exception{
WebConversation wc = new WebConversation();
setCookies(wc, cookies);
PostMethodWebRequest post = new PostMethodWebRequest(SERVLET_URL);
post.setParameter(TrackingServlet.PARAM_D, d);
return wc.sendRequest(post);
}
和常规测试类:
class CookieHandlingTest extends TrackingServletBaseTest {
static{
HttpUnitOptions.setScriptingEnabled(false);
HttpUnitOptions.setExceptionsThrownOnScriptError(false);
}
@Test(groups = 'integration')
void testDummyRequest(){
HttpUnitOptions.setScriptingEnabled(false);
HttpUnitOptions.setExceptionsThrownOnScriptError(false);
def result = sendPostRequest("d", null)
assertThat(result, notNullValue())
}
}
And an error:
testDummyRequest(CookieHandlingTest) Time elapsed: 0.558 sec <<< FAILURE!
java.lang.NoClassDefFoundError: org/mozilla/javascript/Scriptable
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
当我尝试使用 WebConversation 发送请求时发生:
return wc.sendRequest(post);
我做错了什么?