HttpUnit HttpUnitOptions.setScriptingEnabled无效

时间:2014-06-07 16:43:39

标签: java maven testing groovy http-unit

我确实得到了奇怪的错误。 这是我的maven dep:

<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);
        }

groovy测试课:

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);

我做错了什么?

1 个答案:

答案 0 :(得分:2)

java.lang.NoClassDefFoundError: org/mozilla/javascript/Scriptable

包含org.mozilla.javascript.Scriptable.class的jar不在类路径中。添加合适的meven依赖。