【问题标题】:TestNG Parameters are not recognized when using Groups使用组时无法识别 TestNG 参数
【发布时间】:2021-04-27 20:36:39
【问题描述】:

使用 testNG xml 运行测试套件时,测试将正常运行,并且 xml 文件中的所有参数都按预期使用。当我将分组添加到我的@Test 方法并添加组 xml 时,我得到一个失败的:java.lang.nullpointerException。 @Test 在运行类或从 XML 时完美运行。

之前:一切正常

<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd" >
  
<suite name="Suite1" verbose="1" >
    <parameter name="User" value="Admin"/>
    <parameter name="Password" value="something"/>
  <test name="ExampleTest" >
    <classes>
      <class name="test1"/>
      <class name="test2"/>
    </classes>
  </test>
</suite>

之后 - @BeforeClass 因 Null.PointerException 而失败

<suite name="Suite1" verbose="1" >
    <parameter name="User" value="Admin"/>
    <parameter name="Password" value="something"/>
  <test name="ExampleTest" >
          <groups>
              <run>
                  <include name = "setup"/>
                  <exclude name = "functional"/>
                  <include name = "regression"/>
              </run>
          </groups>

    <classes>
      <class name="test1"/>
      <class name="test2"/>
    </classes>
  </test>
</suite>

注意:我已经用 @BeforeClass(groups = {"setup"}) 标记了 @BeforeClass,但它不起作用。

【问题讨论】:

    标签: testng.xml


    【解决方案1】:

    所有,答案是这样的。我的测试类扩展了一个使用@BeforeSuite 和@AfterSuite 的类。当我将 alwaysRun = true 添加到 @BeforeSuite/@AfterSuite 时,它​​按预期工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-14
      • 2013-08-09
      • 2015-02-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多