gpt4 book ai didi

java - 测试组的 TestNG 执行顺序

转载 作者:行者123 更新时间:2023-11-28 20:40:40 25 4
gpt4 key购买 nike

假设我有以下 XML:

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

并且 com.tests 包中的每个测试类只有一个带有不同组注释的测试方法。不在"mats"组中的类的beforeClass()afterClass()方法会被执行吗?

最佳答案

不在指定组中的 Before/After 方法将不会运行,除非它们将 alwaysRun 设置为 true

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.

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.

例如给定以下类:

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()AlwaysTest.beforeSuite() 将被执行。NotAMatsTest.beforeSuite() 不会被执行。

关于java - 测试组的 TestNG 执行顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34637893/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com