简体   繁体   English

测试组的TestNG执行顺序

[英]TestNG execution order for test groups

Say I have the following XML: 说我有以下XML:

<suite name="MATS">
    <test name="mats_test">
    <groups>
        <run>
            <include name="mats" />
        </run>
    </groups>
    <packages>
        <package name="com.tests" />
    </packages>
    </test>
</suite>

And each test class in the com.tests package has only one test method with varying group annotations. com.tests包中的每个测试类只有一种具有不同组注释的测试方法。 Will the beforeClass() and afterClass() methods of classes not in the "mats" group be executed? 是否将执行beforeClass() afterClass() ”组中的类的beforeClass()afterClass()方法?

Before/After methods not in the specified group(s) will not run unless they set alwaysRun to true . 除非它们将alwaysRun设置为true否则不在指定组中的Before / After方法将不会运行。

alwaysRun

For before methods (beforeSuite, beforeTest, beforeTestClass and beforeTestMethod, but not beforeGroups): If set to true, this configuration method will be run regardless of what groups it belongs to. 对于before方法(beforeSuite,beforeTest,beforeTestClass和beforeTestMethod,但不是beforeGroups):如果设置为true,则无论配置文件属于哪个组,都将运行此配置方法。

For after methods (afterSuite, afterClass, ...): If set to true, this configuration method will be run even if one or more methods invoked previously failed or was skipped. 对于after方法(afterSuite,afterClass,...):如果设置为true,则即使先前调用的一个或多个方法失败或被跳过,此配置方法也将运行。

eg Given the following classes: 例如,鉴于以下类别:

public class AMatsTest {
    @BeforeSuite(groups = {"mats"})
    public void beforeSuite() {}
}

public class NotAMatsTest {
    @BeforeSuite
    public void beforeSuite() {}
}

@Test(groups = {"mats"})
public class AnotherMatsTest {
    @BeforeSuite public void beforeSuite() {}
}

public class AlwaysTest {
    @BeforeSuite(alwaysRun = true)
    public void beforeSuite() {}
}

AMatsTest.beforeSuite() , AnotherMatsTest.beforeSuite() , and AlwaysTest.beforeSuite() will be executed. 将执行AMatsTest.beforeSuite()AnotherMatsTest.beforeSuite()AlwaysTest.beforeSuite() NotAMatsTest.beforeSuite() will not be executed. NotAMatsTest.beforeSuite()将不会执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM