在Eclipse插件中动态生成TestNG测试的名称 [英] Names for dynamically generated TestNG tests in Eclipse plugin
问题描述
我使用 @Factory
注释将动态生成的JUnit测试套件转换为TestNG。测试通过扫描包含几个测试规范文件(以DSL编写)的目录并将其加载到知道如何执行它们的测试类中来生成。测试类有一个 @Test
方法命名为 test
,实现 org.testng.ITest
,并根据推荐覆盖 getTestName()
。
I converted a dynamically generated JUnit test suite to TestNG using a @Factory
annotation. The tests are generated by scanning a directory that contains several test specification files (written in a DSL) and by loading them in an test class that knows how to execute them. The test class has a single @Test
method named test
, implements org.testng.ITest
and overrides getTestName()
as recommended.
但是,在TestNG Eclipse UI只显示工厂和执行 test
(尽管按预期执行了几次)。使用JUnit,我将每个规范的名称列为单独的测试。这非常重要,因为几个测试规范可能会失败,我需要查看所有失败(在我的TestNG Eclipse UI中不起作用)。
However, in the TestNG Eclipse UI, only the factory and a single execution of test
is shown (although it is executed several times, as expected). With JUnit, I had the name of each spec listed as a separate test. This is very important because several test specs could fail and I would need to see all failures (which does not work in the TestNG Eclipse UI for me).
我如何实现与TestNG类似的东西?我使用Eclipse TestNG插件6.7.0和testng 6.7。
How can I achieve something similar with TestNG? I use the Eclipse TestNG plugin 6.7.0 and testng 6.7.
推荐答案
尝试在测试类中扩展XmlTest并调用setName() 。我扩展了XmlSuite,并使用setName命名我的测试套件,它是一个类,其中定义了多个测试,并为我工作。其实我刚刚尝试了我在同一个类中所建议的,现在它被称为具有正确名称的测试。我不知道为什么ITest界面被忽略,因为我也尝试了这种方法,没有成功。
Try extending XmlTest in your test class and call setName(). I extended XmlSuite and used setName to name my "test suite" which is a class with multiple tests defined in it and that worked for me. In fact I just tried what I suggested on the same class and now it's called a test with the correct name. I'm not sure why the ITest interface is being ignored as I also tried that approach without success.
这篇关于在Eclipse插件中动态生成TestNG测试的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!