通过命令行通过批处理文件运行时,测试被跳过,但是这些测试在Eclipse IDE上执行
我正在使用RestAssured框架编写用于API测试的Java代码,并且希望通过命令行上的批处理文件执行脚本,但是目前,我的测试已在命令行上跳过,但是可以在Eclipse IDE上正确执行
set classpath=C:\Users\Daffolap-624\workspace\WapandaParallel1\bin;C:\Users\Daffolap-624\workspace\WapandaParallel1\lib\*;C:\Users\Daffolap-624\workspace\WapandaParallel1\lib\Rest-Assured_jar_files\rest-assured-3.3.0.jar;C:\Users\Daffolap-624\workspace\WapandaParallel1\lib\Rest-Assured_jar_files\groovy-2.4.6;C:\Users\Daffolap-624\workspace\WapandaParallel1\lib\Rest-Assured_jar_files\rest-assured-3.3.0.jar;C:\Users\Daffolap-624\workspace\WapandaParallel1\lib\Rest-Assured_jar_files\groovy-json-2.4.6;C:\Users\Daffolap-624\workspace\WapandaParallel1\lib\Rest-Assured_jar_files\groovy-xml-2.4.6;C:\Users\Daffolap-624\workspace\WapandaParallel1\lib\Rest-Assured_jar_files\groovy-all-2.4.16.jar
java org.testng.TestNG -log 10 C:\Users\Daffolap-624\workspace\WapandaParallel1\testng.xml
pause
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test thread-count="5" name="Test">
<classes>
<class name="API_Automation.ApiOperationsTest"/>
</classes>
</test>
</suite>
所以那是我的批处理文件和testng.xml文件 通过编辑XML文件以获得跳过的测试描述,我知道我的测试在通过命令行运行代码时抛出了异常 以下是例外情况-
[TestNG] RUNNING: Suite: "Test" containing "1" Tests (config: C:\Users\Daffolap-624\workspace\WapandaParallel1\testng.xml)
[TestNG] INVOKING CONFIGURATION: "Test" - @BeforeTest API_Automation.ApiOperationsTest.StartDriver()
[TestNG] FAILED CONFIGURATION: "Test" - @BeforeTest API_Automation.ApiOperationsTest.StartDriver() finished in 1245 ms
[TestNG] java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient
[TestNG] at io.restassured.config.HttpClientConfig.defaultHttpClientFactory(HttpClientConfig.java:264)
[TestNG] at io.restassured.config.HttpClientConfig.<init>(HttpClientConfig.java:76)
[TestNG] at io.restassured.config.RestAssuredConfig.<init>(RestAssuredConfig.java:41)
[TestNG] at io.restassured.RestAssured.<clinit>(RestAssured.java:420)
[TestNG] at API_Automation.ApiOperationsTest.StartDriver(ApiOperationsTest.java:36)
[TestNG] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[TestNG] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
[TestNG] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
[TestNG] at java.lang.reflect.Method.invoke(Unknown Source)
[TestNG] at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108)
[TestNG] at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:523)
[TestNG] at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:224)
[TestNG] at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:146)
[TestNG] at org.testng.TestRunner.beforeRun(TestRunner.java:626)
[TestNG] at org.testng.TestRunner.run(TestRunner.java:594)
[TestNG] at org.testng.SuiteRunner.runTest(SuiteRunner.java:380)
[TestNG] at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375)
[TestNG] at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
[TestNG] at org.testng.SuiteRunner.run(SuiteRunner.java:289)
[TestNG] at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
[TestNG] at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
[TestNG] at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301)
[TestNG] at org.testng.TestNG.runSuitesLocally(TestNG.java:1226)
[TestNG] at org.testng.TestNG.runSuites(TestNG.java:1144)
[TestNG] at org.testng.TestNG.run(TestNG.java:1115)
[TestNG] at org.testng.TestNG.privateMain(TestNG.java:1442)
[TestNG] at org.testng.TestNG.main(TestNG.java:1411)
[TestNG] Caused by: java.lang.ClassNotFoundException: org.apache.http.client.HttpClient
[TestNG] at java.net.URLClassLoader.findClass(Unknown Source)
[TestNG] at java.lang.ClassLoader.loadClass(Unknown Source)
[TestNG] at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
[TestNG] at java.lang.ClassLoader.loadClass(Unknown Source)
[TestNG] ... 27 more
[TestNG] SKIPPED: "Test" - API_Automation.ApiOperationsTest.CompleteFlow() finished in 0 ms
一方面,我确定程序无法在运行时从lib文件夹中获取jar文件。 而且,如果我在Classpath中提到了特定jar文件的路径,那么该文件将解决异常。
为什么程序在运行时无法在lib文件夹中获取jar文件。为什么它仅访问那些在Classpath中提到了直接路径的jar文件?
答案 0 :(得分:0)
您的批处理文件设置的类路径可能不包含应该从中获取HttpClient
(未找到的类)的库,而IDE中的项目配置中确实包含该库。它的类路径,因此可以在IDE中使用。
要验证是否是这种情况,请在测试中添加一条语句以打印出当前的类路径,并查看从IDE运行时是否相同:System.out.println(System.getProperty("java.class.path"))
在这种情况下,您需要修改批处理文件中类路径的设置,并在其中添加缺少类的库所在的路径。