Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
776 views
in Technique[技术] by (71.8m points)

testng.xml - TestNG Parameters are not recognized when using Groups

When running test suite using testNG xml, the test will run fine and all of the parameters from the xml file are used as expected. The moment I added grouping to my @Test Methods, and add the groups xml I get a failed:java.lang.nullpointerException. The @Test run perfectly when running the Class or from the XML.

BEFORE: All runs fine

<!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>

AFTER - @BeforeClass fails with 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>

NOTE: I've tagged the @BeforeClass with @BeforeClass(groups = {"setup"}) and it does not work.

question from:https://stackoverflow.com/questions/65861057/testng-parameters-are-not-recognized-when-using-groups

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

All, the answer is this. My test class extends a class that uses a @BeforeSuite and @AfterSuite. When I added alwaysRun = true to the @BeforeSuite/@AfterSuite it worked as expected.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...