我正在为Web应用程序创建测试自动化脚本。 我想为JSP文件编写测试文件。 对于JSP我正在使用JwebUnit库。 我按如下方式创建了测试文件:
class Junittest {
@Before
public void prepare() {
setTestingEngineKey(TestingEngineRegistry.TESTING_ENGINE_HTMLUNIT);
setBaseUrl("http://localhost:8081/JSPServer/jsp/");
}
@Test
public void test() {
beginAt("home.jsp");
assertTitleEquals("Echoing HTML Request Parameters");
}
}
当我尝试运行JUnit测试时,它给出了异常,如下所示:
java.lang.NoClassDefFoundError: org/apache/regexp/RESyntaxException
at net.sourceforge.jwebunit.junit.JWebUnit.getTester(JWebUnit.java:62)
at net.sourceforge.jwebunit.junit.JWebUnit.beginAt(JWebUnit.java:167)
at serv.Junittest.test(Junittest.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:389)
at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:115)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:167)
at org.junit.jupiter.engine.execution.ThrowableCollector.execute(ThrowableCollector.java:40)
我把home.jsp文件放在JSPServer中 - > webcontent - > JSP。
当我尝试在服务器上运行文件时,它正常工作。当我尝试运行JUnit测试时,它给出了上述异常。那么有人可以建议我解决这个问题吗?
答案 0 :(得分:0)
它的构建路径中缺少一个库(最佳猜测Jakarta Regexp
jar)。将jar添加到构建路径中。可能只是解决你的问题。