1

我正在为 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 测试时,它给出了上述异常。所以有人可以建议我解决这个问题吗?

4

1 回答 1

0

它在其构建路径中缺少一个库(最佳猜测Jakarta Regexpjar)。将 jar 添加到构建路径。可能只是解决你的问题。

于 2018-04-18T12:33:05.967 回答