【问题标题】:HttpUnit HttpUnitOptions.setScriptingEnabled not workingHttpUnit HttpUnitOptions.setScriptingEnabled 不起作用
【发布时间】:2014-06-07 16:43:39
【问题描述】:

我确实遇到了奇怪的错误。 这是我的 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);
        }

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

我做错了什么?

【问题讨论】:

    标签: java maven testing groovy http-unit


    【解决方案1】:
    java.lang.NoClassDefFoundError: org/mozilla/javascript/Scriptable
    

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

    【讨论】:

    • 我想禁用脚本解释。 httpunit.sourceforge.net/doc/faq.html#disable 脚本
    • 但是使用的类仍然可能引用这个和其他 JavaScript 类。因此,无论如何添加库,并且在您编码后,禁用脚本执行。
    • 你是对的,它有帮助。我认为禁用的脚本解释不需要脚本引擎的依赖...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-27
    • 2018-10-30
    • 2011-06-19
    • 2014-10-20
    • 2012-04-01
    • 1970-01-01
    相关资源
    最近更新 更多