如何防止TestNG组中的拼写错误? [英] How to prevent spelling mistakes in TestNG groups?

查看:59
本文介绍了如何防止TestNG组中的拼写错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们刚刚开始使用TestNG来执行我们的测试.现在,我们已经定义了四个组来安排我们的测试(即GroupA,GroupB,GroupC和GroupD).

We have just started to use TestNG to implement our tests. Now we have defined four groups to arrange our tests (i.e GroupA, GroupB, GroupC and GroupD).

TestNG是否可以通过使用这些组来防止拼写错误?

@Test(groups = {"GroupA", "GoupB"})    

我们如何建议开发人员"GroupB"中的拼写错误(缺少r)?仅允许组的预定义名称的可能性也可以.

How can we advice a developer of the spelling mistake in "GroupB" (missing r) ? Also a possibility to just allow predefined names for groups would be OK.

一个想法是定义代码模板,可以通过template.xml将其包含到Eclipse中.但这似乎对开发人员不友好.

One idea was do define code templates, which could be included to Eclipse via template.xml. But this seems not to be developer-friendly.

任何其他想法将不胜感激.

Any other idea would be appreciated.

谢谢.

推荐答案

只需使用常量...

您可以使用带有常量的专用类,如:

You can have dedicated class with constants like:

public class TestType {
    private static final String GROUP_A = "GroupA";
    private static final String GROUP_B = "GroupB"

    /**
     * Avoid instantiation
     */
    private TestType() {
    }
}

和:

 @Test(groups = {TestType.GROUP_B, TestType.GROUP_A})    

这对我们来说很好.唯一的小问题(如果使用的是Maven)是,您必须在每个单独的项目中都有这样的类,或者将其提取到一些常见的测试Jar中.因为默认情况下,Maven不允许共享测试依赖项.(我知道可以在使用特殊的Maven修补插件的项目之间共享测试jar,但是不会再走这条路了.)

This works for us fine. The only small problem (if you are using Maven) is that you have to have such class in each separate project or extract it into some common testing Jar. Because Maven doesn't allow to share test dependencies by default. (I am aware of posibility to share test jars between projects with special maven patched plugin, but wouldn't go that path once again.)

在核心评论中推广使用这些常量.

Promote using these constants during core reviews.

顺便说一句,错过的考试应该以较低的考试覆盖率出现.

BTW, missed test should come up in lower test coverage ratio.

这篇关于如何防止TestNG组中的拼写错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆