Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Junit JMock HttpServletRequest设置参数_Junit_Jmock - Fatal编程技术网

Junit JMock HttpServletRequest设置参数

Junit JMock HttpServletRequest设置参数,junit,jmock,Junit,Jmock,如何在JMock中的HttpServletRequest中设置参数?我在谷歌搜索,很多都是旧的和不推荐的方法。官方网站只是告诉我如何使用这些工具,但没有说明如何为HttpServletRequest设置参数 请准备一些指南。谢谢。现在找到了方法,只是使用了new expections()语法 首先,最好对参数使用allowing()子句。这表明这是一个查询,不会破坏对无关更改的测试。其次,您拥有的allowing()子句将返回默认值(可能为null)。这就是你想要的吗?第三,你在这里测试什么?我

如何在JMock中的HttpServletRequest中设置参数?我在谷歌搜索,很多都是旧的和不推荐的方法。官方网站只是告诉我如何使用这些工具,但没有说明如何为HttpServletRequest设置参数


请准备一些指南。谢谢。

现在找到了方法,只是使用了new expections()语法


首先,最好对参数使用allowing()子句。这表明这是一个查询,不会破坏对无关更改的测试。其次,您拥有的allowing()子句将返回默认值(可能为null)。这就是你想要的吗?第三,你在这里测试什么?我倾向于编写在文本和域之间转换的助手对象,然后使用端到端测试来测试整个过程。
    context.checking(new Expectations() {{
        oneOf(req).getParameter("sitename"); will(returnValue(siteName));
        oneOf(req).getParameter("pagename"); will(returnValue(pageName));
        oneOf(req).getParameter("textcolor"); will(returnValue(textColor));
        oneOf(req).getParameter("buttoncolor"); will(returnValue(buttonColor));
        oneOf(req).getParameter("bordercolor"); will(returnValue(borderColor));
        oneOf(req).getParameter("subscribetext"); will(returnValue(subscribeText));
        oneOf(req).getParameter("unsubscribetext"); will(returnValue(unsubscribeText));
        allowing(req).getRequestDispatcher(result);
        allowing(req).getRequestURL();
    }});