1

我在做什么:使用 Jenkins 针对各种环境运行相同的测试套件和测试用例 - 开发/登台/生产。我正在使用带有 Java 实现和 TestNG 的 WebDriver。

我想做的:有选择地禁用一些测试,但不是整个测试套件,根据环境运行。我不想在环境之间维护单独的代码库,而是想知道一种方法来实现这一点。

最初的想法:我正在考虑在 Jenkins 中为每个环境中的每个作业设置一个系统属性,每个测试装饰器都必须提取这条信息以确定是否应该运行它。我认为这很笨拙,我不确定该怎么做,而且我不确定这是否是正确的方法。

有人能告诉我实现这一目标的最佳方法吗?我希望这不是最好的方法。

谢谢,

4

3 回答 3

1

Have you looked at TestNG listeners?

You can write a listener which just before the berfore test suite is run BUT after the tests to run have been identifier, to iterate around the list of tests and remove tests you do not want to run. Because this is programatic you can write any java to achieve what you want.

Also, you could create annotations to identify which tests run in which environment; e.g annotate those tests with something like @RunInEnvironment({"UAT", INT"}); Your listener could then use those annotations to remove tests from the list which are not required.

于 2013-08-24T07:26:36.237 回答
0

我认为团体是你的答案。使用 TestNG,您可以包含/排除组。您只需要定义哪些测试属于哪些组。

http://testng.org/doc/documentation-main.html#exclusions

于 2013-08-23T23:47:54.933 回答
0

@MrTi 这个解决方案相当静态,我相信他想要更多的动态性。

如果可以在启动时检测您的环境,您可以尝试该线程中描述的解决方案之一。这个框架也可能有用:https ://github.com/wolfs/testng-rules

注意:在 JUnit 上,您将使用规则https://github.com/lacostej/web-validators/commit/2e1af8e1d9d1bf206849702d4231961563457815(实现使用旧 API)

于 2013-08-24T06:41:55.327 回答