How to pass parameters to guicified TestNG test from Surefire Maven plugin?

只谈情不闲聊 提交于 2019-12-06 20:48:24

I just ran a quick test and properties seem to be passed correctly to TestNG:

    <configuration>
      <suiteXmlFiles>
        <suiteXmlFile>src/test/resources/testng-single.yaml</suiteXmlFile>
      </suiteXmlFiles>
      <systemPropertyVariables>
        <foo>bar</foo>
      </systemPropertyVariables>

My suite file calls the test class B, which contains:

@Test
public void f() {
  System.out.println(" property:" + System.getProperty("foo"));
}

and running it with Maven shows:

property:bar
Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.358 sec

I'm not using Guice in this simple example but that's the only difference between your code and mine.

Feel free to create a small Maven project reproducing your problem, make sure that I can compile it and then email it to me.

I tried below test and works fine

My Pom file

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.12.4</version>
                <configuration>
                    <!--<groups>Regression</groups> -->
                    <systemPropertyVariables>
                        <environment>UAT</environment>
                    </systemPropertyVariables>
                </configuration>
            </plugin>
        </plugins>
    </build>

My TestNG test

import org.testng.annotations.Parameters;
import org.testng.annotations.Test;


public class TestAuthentication {

    @Test (groups = { "Sniff", "Regression" })
    public void validAuthenticationTest(){
        System.out.println(" property:" + System.getProperty("environment"));
    }

    @Test (groups = { "Regression" },parameters = {"environment"})
    public void failedAuthenticationTest(String environment){
        System.out.println("Regression-"+environment);
    }

    @Parameters("environment")
    @Test (groups = { "Sniff"})
    public void newUserAuthenticationTest(String environment){
        System.out.println("Sniff-"+environment);
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!