只有 1 个测试 class 是 运行 并且 TestNG 执行挂起
Only 1 test class is running and TestNG execution hangs
我有 2 个测试 classes - PostTests
和 UserTests
。我在 testng.xml
文件中指定了它们,当 运行 使用 maven 时,我看到在 testng 中第一个指定的 class 的所有方法都是 运行 并且它挂起。 ...class 2 个方法不是运行。它挂了。
你能帮我看看我做错了什么吗?
下面是我的testng.xml
<suite name="TestAll">
<test name="post">
<classes>
<class name="com.vin.vinapi.PostTests"/>
</classes>
</test>
<test name="user">
<classes>
<class name="com.vin.vinapi.UserTests"/>
</classes>
</test>
</suite>
执行结果如下
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building vinapi 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for com.google.code.gson:gson:jar:2.2.4 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ vinapi ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/i332939/Documents/workspace/vinapi/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ vinapi ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ vinapi ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/i332939/Documents/workspace/vinapi/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ vinapi ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ vinapi ---
[INFO] Surefire report directory: /Users/i332939/Documents/workspace/vinapi/target/surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running TestSuite
Request URL : https://jsonplaceholder.typicode.com/posts
Response Code : 200
Request URL : https://jsonplaceholder.typicode.com/posts/2
Response Code : 200
Request URL : https://jsonplaceholder.typicode.com/users
如您所见,PostTests.java
(/posts
和 /posts/2
)中的 2 个测试已执行,UserTests
中的 1 个测试(/users
)开始并它只挂在那里
当我将 UserTests
移动到 testng.xml
中的 PostTests
上方时,UserTests
的所有测试都在执行,当 PostTests
的 1 个测试开始时它挂起.
通过命令行或 eclipse 运行 时输出相同。
你能不能把 class 组合成一个 class 喜欢
<suite name="TestAll">
<test name="post">
<classes>
<class name="com.vin.vinapi.PostTests"/>
<class name="com.vin.vinapi.UserTests"/>
</classes>
</test>
</suite>
如果工作正常,则可能是连接在处理请求时进入了死锁状态。
是否在每个 class.
中分别创建了连接
我有 2 个测试 classes - PostTests
和 UserTests
。我在 testng.xml
文件中指定了它们,当 运行 使用 maven 时,我看到在 testng 中第一个指定的 class 的所有方法都是 运行 并且它挂起。 ...class 2 个方法不是运行。它挂了。
你能帮我看看我做错了什么吗?
下面是我的testng.xml
<suite name="TestAll">
<test name="post">
<classes>
<class name="com.vin.vinapi.PostTests"/>
</classes>
</test>
<test name="user">
<classes>
<class name="com.vin.vinapi.UserTests"/>
</classes>
</test>
</suite>
执行结果如下
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building vinapi 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for com.google.code.gson:gson:jar:2.2.4 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ vinapi ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/i332939/Documents/workspace/vinapi/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ vinapi ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ vinapi ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/i332939/Documents/workspace/vinapi/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ vinapi ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ vinapi ---
[INFO] Surefire report directory: /Users/i332939/Documents/workspace/vinapi/target/surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running TestSuite
Request URL : https://jsonplaceholder.typicode.com/posts
Response Code : 200
Request URL : https://jsonplaceholder.typicode.com/posts/2
Response Code : 200
Request URL : https://jsonplaceholder.typicode.com/users
如您所见,PostTests.java
(/posts
和 /posts/2
)中的 2 个测试已执行,UserTests
中的 1 个测试(/users
)开始并它只挂在那里
当我将 UserTests
移动到 testng.xml
中的 PostTests
上方时,UserTests
的所有测试都在执行,当 PostTests
的 1 个测试开始时它挂起.
通过命令行或 eclipse 运行 时输出相同。
你能不能把 class 组合成一个 class 喜欢
<suite name="TestAll">
<test name="post">
<classes>
<class name="com.vin.vinapi.PostTests"/>
<class name="com.vin.vinapi.UserTests"/>
</classes>
</test>
</suite>
如果工作正常,则可能是连接在处理请求时进入了死锁状态。
是否在每个 class.
中分别创建了连接