当 运行 通过批处理文件但在 eclipse ide 上执行时测试被跳过

test are skipped when running via batch file but are executing on eclipse ide

当 运行 通过命令行上的批处理文件时,测试将被跳过,但这些测试是在 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 文件以获取跳过测试的描述,我知道我的测试在通过命令行 运行ning 代码时抛出异常 以下是例外-

[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 文件。 如果我在类路径中提到特定 jar 文件的路径,则该文件异常已解决。

为什么程序无法在 运行 时间在 lib 中获取 jar 文件 folder.Why 是否它只访问那些 jar 文件,其直接路径在 Classpath 中提到?

您的批处理文件设置的 class 路径可能不包含应该从中获取 HttpClient(未找到的 class)的库,而IDE 中的项目配置确实在其 class 路径中包含该库,因此它在 IDE.

中工作

要验证是否是这种情况,请在您的测试中添加一条语句以打印出当前 class 路径,并查看当您从 IDE 运行 时它是否相同: System.out.println(System.getProperty("java.class.path"))

如果是这种情况,您需要修改批处理文件中 classpath 的设置,将缺少 classes 的库所在的路径添加到其中。