SoapUI: 5.6.0 java.lang.ClassNotFoundException: PostgreSQL/org.postgresql.Driver when 运行 tests using maven
SoapUI: 5.6.0 java.lang.ClassNotFoundException: PostgreSQL/org.postgresql.Driver when running tests using maven
我正在尝试使用 mvn 命令 运行 SoapUI 测试,尽管测试通过并访问了数据库,但我在每个 JDBC 请求中都看到了这个异常。"
在maven中添加了PostgreSQL的依赖。
日志:
5:20:54,484 INFO [SoapUITestCaseRunner] running step [Check db to make sure it was removed]
java.lang.ClassNotFoundException: PostgreSQL/org.postgresql.Driver
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:398)
at com.eviware.soapui.support.GroovyUtils.registerJdbcDriver(GroovyUtils.java:103)
at com.eviware.soapui.support.jdbc.JdbcUtils.initConnection(JdbcUtils.java:50)
at com.eviware.soapui.impl.wsdl.panels.teststeps.JdbcSubmit.getDatabaseConnection(JdbcSubmit.java:190)
at com.eviware.soapui.impl.wsdl.panels.teststeps.JdbcSubmit.prepare(JdbcSubmit.java:222)
at com.eviware.soapui.impl.wsdl.panels.teststeps.JdbcSubmit.runQuery(JdbcSubmit.java:173)
at com.eviware.soapui.impl.wsdl.panels.teststeps.JdbcSubmit.run(JdbcSubmit.java:147)
at com.eviware.soapui.impl.wsdl.panels.teststeps.JdbcSubmit.<init>(JdbcSubmit.java:79)
at com.eviware.soapui.impl.wsdl.panels.teststeps.JdbcRequest.submit(JdbcRequest.java:122)
at com.eviware.soapui.impl.wsdl.teststeps.JdbcRequestTestStep.run(JdbcRequestTestStep.java:194)
at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.runTestStep(AbstractTestCaseRunner.java:211)
at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner.runCurrentTestStep(WsdlTestCaseRunner.java:47)
at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.internalRun(AbstractTestCaseRunner.java:138)
at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.internalRun(AbstractTestCaseRunner.java:46)
at com.eviware.soapui.impl.wsdl.support.AbstractTestRunner.run(AbstractTestRunner.java:128)
at com.eviware.soapui.impl.wsdl.support.AbstractTestRunner.start(AbstractTestRunner.java:76)
at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase.run(WsdlTestCase.java:594)
at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase.run(WsdlTestCase.java:78)
at com.eviware.soapui.model.testsuite.TestCase$run.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:136)
at Script1.run(Script1.groovy:7)
at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:90)
at com.eviware.soapui.impl.wsdl.WsdlTestSuite.runTearDownScript(WsdlTestSuite.java:495)
at com.eviware.soapui.impl.wsdl.testcase.WsdlTestSuiteRunner.internalFinally(WsdlTestSuiteRunner.java:163)
at com.eviware.soapui.impl.wsdl.testcase.WsdlTestSuiteRunner.internalFinally(WsdlTestSuiteRunner.java:46)
at com.eviware.soapui.impl.wsdl.support.AbstractTestRunner.run(AbstractTestRunner.java:149)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
15:20:54,589 INFO [SoapUITestCaseRunner] Assertion [JDBC Status] has status VALID
15:20:54,589 INFO [SoapUITestCaseRunner] Assertion [JDBC Timeout] has status VALID
15:20:54,592 INFO [SoapUITestCaseRunner] Assertion [XPath Match] has status VALID
15:20:54,595 INFO [log] Teardown script finished.
pom.xml:
<properties>
<soapui-maven-plugin.version>5.6.0</soapui-maven-plugin.version>
<postgreSql.version>42.2.20</postgreSql.version>
</properties>
<pluginRepositories>
<pluginRepository>
<id>SmartBearPluginRepository</id>
<url>https://rapi.tools.ops.smartbear.io/nexus/content/groups/public/</url>
</pluginRepository>
</pluginRepositories>
<build>
<plugins>
<!-- Plugin to read external properties file -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0.0</version><!-- afaik it's final, no need for parameter -->
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>project.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
<!-- SoapUI plugin -->
<plugin>
<groupId>com.smartbear.soapui</groupId>
<artifactId>soapui-maven-plugin</artifactId>
<version>${soapui-maven-plugin.version}</version>
<configuration>
<printReport>true</printReport>
<junitReport>true</junitReport>
<outputFolder>${baseDir}/target/surefire-reports</outputFolder>
</configuration>
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgreSql.version}</version>
</dependency>
</dependencies>
注意:留下 groupid 和执行。
知道什么会导致异常,或者如何抑制它?对我来说奇怪的是 JDBC 请求 运行 没有问题。
我 Java 可以从类路径自动加载 JDBC 驱动程序,这就是它仍然有效的原因。
我认为您的 Groovy 拆解脚本中有一行看起来像这样:
def driver = 'PostgreSQL/org.postgresql.Driver'
如果将其替换为
def driver = 'org.postgresql.Driver'
它应该可以正常工作。
更新:提问者通过在脚本中添加这一行解决了这个问题:
com.eviware.soapui.support.GroovyUtils.registerJdbcDriver(driver)
这有点 hack,但它使异常消失了。
我正在尝试使用 mvn 命令 运行 SoapUI 测试,尽管测试通过并访问了数据库,但我在每个 JDBC 请求中都看到了这个异常。"
在maven中添加了PostgreSQL的依赖。
日志:
5:20:54,484 INFO [SoapUITestCaseRunner] running step [Check db to make sure it was removed]
java.lang.ClassNotFoundException: PostgreSQL/org.postgresql.Driver
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:398)
at com.eviware.soapui.support.GroovyUtils.registerJdbcDriver(GroovyUtils.java:103)
at com.eviware.soapui.support.jdbc.JdbcUtils.initConnection(JdbcUtils.java:50)
at com.eviware.soapui.impl.wsdl.panels.teststeps.JdbcSubmit.getDatabaseConnection(JdbcSubmit.java:190)
at com.eviware.soapui.impl.wsdl.panels.teststeps.JdbcSubmit.prepare(JdbcSubmit.java:222)
at com.eviware.soapui.impl.wsdl.panels.teststeps.JdbcSubmit.runQuery(JdbcSubmit.java:173)
at com.eviware.soapui.impl.wsdl.panels.teststeps.JdbcSubmit.run(JdbcSubmit.java:147)
at com.eviware.soapui.impl.wsdl.panels.teststeps.JdbcSubmit.<init>(JdbcSubmit.java:79)
at com.eviware.soapui.impl.wsdl.panels.teststeps.JdbcRequest.submit(JdbcRequest.java:122)
at com.eviware.soapui.impl.wsdl.teststeps.JdbcRequestTestStep.run(JdbcRequestTestStep.java:194)
at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.runTestStep(AbstractTestCaseRunner.java:211)
at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner.runCurrentTestStep(WsdlTestCaseRunner.java:47)
at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.internalRun(AbstractTestCaseRunner.java:138)
at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.internalRun(AbstractTestCaseRunner.java:46)
at com.eviware.soapui.impl.wsdl.support.AbstractTestRunner.run(AbstractTestRunner.java:128)
at com.eviware.soapui.impl.wsdl.support.AbstractTestRunner.start(AbstractTestRunner.java:76)
at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase.run(WsdlTestCase.java:594)
at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase.run(WsdlTestCase.java:78)
at com.eviware.soapui.model.testsuite.TestCase$run.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:136)
at Script1.run(Script1.groovy:7)
at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:90)
at com.eviware.soapui.impl.wsdl.WsdlTestSuite.runTearDownScript(WsdlTestSuite.java:495)
at com.eviware.soapui.impl.wsdl.testcase.WsdlTestSuiteRunner.internalFinally(WsdlTestSuiteRunner.java:163)
at com.eviware.soapui.impl.wsdl.testcase.WsdlTestSuiteRunner.internalFinally(WsdlTestSuiteRunner.java:46)
at com.eviware.soapui.impl.wsdl.support.AbstractTestRunner.run(AbstractTestRunner.java:149)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
15:20:54,589 INFO [SoapUITestCaseRunner] Assertion [JDBC Status] has status VALID
15:20:54,589 INFO [SoapUITestCaseRunner] Assertion [JDBC Timeout] has status VALID
15:20:54,592 INFO [SoapUITestCaseRunner] Assertion [XPath Match] has status VALID
15:20:54,595 INFO [log] Teardown script finished.
pom.xml:
<properties>
<soapui-maven-plugin.version>5.6.0</soapui-maven-plugin.version>
<postgreSql.version>42.2.20</postgreSql.version>
</properties>
<pluginRepositories>
<pluginRepository>
<id>SmartBearPluginRepository</id>
<url>https://rapi.tools.ops.smartbear.io/nexus/content/groups/public/</url>
</pluginRepository>
</pluginRepositories>
<build>
<plugins>
<!-- Plugin to read external properties file -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0.0</version><!-- afaik it's final, no need for parameter -->
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>project.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
<!-- SoapUI plugin -->
<plugin>
<groupId>com.smartbear.soapui</groupId>
<artifactId>soapui-maven-plugin</artifactId>
<version>${soapui-maven-plugin.version}</version>
<configuration>
<printReport>true</printReport>
<junitReport>true</junitReport>
<outputFolder>${baseDir}/target/surefire-reports</outputFolder>
</configuration>
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgreSql.version}</version>
</dependency>
</dependencies>
注意:留下 groupid 和执行。
知道什么会导致异常,或者如何抑制它?对我来说奇怪的是 JDBC 请求 运行 没有问题。
我 Java 可以从类路径自动加载 JDBC 驱动程序,这就是它仍然有效的原因。
我认为您的 Groovy 拆解脚本中有一行看起来像这样:
def driver = 'PostgreSQL/org.postgresql.Driver'
如果将其替换为
def driver = 'org.postgresql.Driver'
它应该可以正常工作。
更新:提问者通过在脚本中添加这一行解决了这个问题:
com.eviware.soapui.support.GroovyUtils.registerJdbcDriver(driver)
这有点 hack,但它使异常消失了。