Java TestNG 未在测试套件中运行测试
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22457326/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
TestNG not running tests in testing suite
提问by ILikeTacos
I'm trying to run a testing suite using XML and TestNG, but I'm always getting the same message using both: Eclipse and the command line:
我正在尝试使用 XML 和 TestNG 运行测试套件,但我总是收到相同的消息:Eclipse 和命令行:
[TestNG] Running:
/Users/achavez/Programs/Selenium/java/src/tests/resources/testng.xml
===============================================
TestingSuite1
Total tests run: 0, Failures: 0, Skips: 0
===============================================
The file is read correctly, but it seems like the tests are not running.
该文件已正确读取,但似乎没有运行测试。
These are the contents of my testng.xml:
这些是我的 testng.xml 的内容:
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="TestingSuite1" verbose="1">
<test name="Test1" >
<packages>
<package name="tests"/>
</packages>
</test>
</suite>
and this is how my directory structure looks like in Eclipse:
这就是我的目录结构在 Eclipse 中的样子:
Also, this is also how I'm attempting to run the testing suite through the command line:
此外,这也是我尝试通过命令行运行测试套件的方式:
java -jar /Applications/Zend\ Studio.app/Contents/Resources/Java/plugins/org.testng.eclipse_6.8.6.20141201_2240/lib/testng.jar src/tests/resources/testng.xml
I've tried cleaning the project through eclipse, and that didn't seem to help. I also tried running:
我试过通过 eclipse 清理项目,但这似乎没有帮助。我也试过运行:
mvn clean
but it didn't do the job either.
mvn clean
但它也没有完成工作。
Any help pointing me to the right direction will be greatly appreciated!
任何为我指明正确方向的帮助将不胜感激!
采纳答案by teejay
You could also check imports for imported Test annotation, should be:
您还可以检查导入的 Test 注释的导入,应该是:
import org.testng.annotations.Test;
@Test
public myTest(){ ... }
and not for example:
而不是例如:
import org.junit.Test;
回答by ILikeTacos
Apparently, TestNG is wrong regarding generating the XML file for the testing suite.
显然,TestNG 在为测试套件生成 XML 文件方面是错误的。
Even though following their instructions to the letter, my tests were not running. I ended up with this testng.xml
file and my tests, started to run:
即使按照他们的指示去做,我的测试也没有运行。我最终得到了这个testng.xml
文件,我的测试开始运行:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="TestingSuite" parallel="none">
<test name="Test1">
<classes>
<class name="tests.Page1"/>
</classes>
</test>
<test name="Test 2">
<classes>
<class name="tests.Page2"/>
</classes>
</test>
</suite>
回答by sue
In my case, the test was accidentally marked as "enabled = false" inside the @Test(...). Make sure the value for you is marked as "true".
就我而言,该测试在@Test(...) 中被意外标记为“enabled = false”。确保您的值被标记为“true”。
回答by Yolan Moodley
I experienced a similar issue and it was resolved by performing a project clean within Eclipse (Project-> Clean-> Clean Selected project)
我遇到了类似的问题,并通过在 Eclipse 中执行项目清理(项目-> 清理-> 清理选定项目)解决了这个问题
回答by Sindhu
I had to change my method access modifier to public from private to get it working .
我不得不将我的方法访问修饰符从私有更改为 public 以使其正常工作。
回答by Arwen
In my case, the @Test annotation was imported automatically by IDE as import org.junit.Test
.
就我而言,@Test 批注由 IDE 自动导入为import org.junit.Test
.
After changing it to import org.testng.annotations.Test
the tests got picked up correctly.
将其更改为import org.testng.annotations.Test
测试后,正确拾取。
回答by jumps4fun
I also had this problem, and none of the above solutions worked. Restarting Eclipse, however, did. I know this seems like an unnecessary answer, but I myself would have saved a lot of time if I had done it sooner, so I'll post it anyway.
我也遇到了这个问题,以上解决方案都没有奏效。然而,重新启动 Eclipse 确实如此。我知道这似乎是一个不必要的答案,但如果我早点完成,我自己会节省很多时间,所以我还是会发布它。
回答by Алексей Пермяков
I had the same problem and here is my results: In my project I had test file in
我遇到了同样的问题,这是我的结果:在我的项目中,我有测试文件
src/test/java/com/temporary/core
and in the same time I had resources for the test in
同时我有测试的资源
src/test/resources/com/temporary/Core
As I found, testng tried to find test file in the second directory.
正如我发现的,testng 试图在第二个目录中找到测试文件。
When I renamed directory with resources from Core to tcore, the problem was fixed.
当我将包含资源的目录从 Core 重命名为 tcore 时,问题得到解决。
回答by Richie_b
I had this same issue, here is what worked for me:
我遇到了同样的问题,这对我有用:
I put all of the TestNG libraries in a separate lib folder in my project
a.
com.beust.jcommander_1.72.0.jar
b.
org.apache-extras.beanshell.bsh_2.0.0.b6.jar
c.
org.testng_6.14.2.r201802161450.jar
d.
or.yaml.snakeyaml_1.17.0.jar
I also put a copy of selenium-server and chromedriver in the lib folder as well
From my project folder (with
testng.xml
located in the project root) I ran:java -cp .\lib\*;.\target\classes org.testng.TestNG testng.xml
我把所有的 TestNG 库放在我项目的一个单独的 lib 文件夹中
一种。
com.beust.jcommander_1.72.0.jar
湾
org.apache-extras.beanshell.bsh_2.0.0.b6.jar
C。
org.testng_6.14.2.r201802161450.jar
d.
or.yaml.snakeyaml_1.17.0.jar
我还在 lib 文件夹中放了一份 selenium-server 和 chromedriver 的副本
从我的项目文件夹(
testng.xml
位于项目根目录中)我运行:java -cp .\lib\*;.\target\classes org.testng.TestNG testng.xml
回答by Pavan Test
I was facing the same issue , i have updated/installed TestNG from eclipse marketplace it worked for me
我遇到了同样的问题,我已经从 eclipse 市场更新/安装了 TestNG,它对我有用