简体   繁体   中英

Executing single TestNG test case with using Maven/Jenkins

Can anyone tell me how to execute single testcase with maven or jenkins.
mvn -Dtest=smoke tests seem to be not working for me. I have tried other options like mvn clean install -Dtest=smoketest test that time i got below error if is set to true, and no tests execute if set to false` Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test (default-test) on project ABC: No tests were executed! (Set -DfailIfNoTests=false to ignore this error.)

POM USED

<project>
    <groupId>com.testng.smoke</groupId>
    <artifactId>ABC</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <build> <!-- Source directory configuration -->
    <sourceDirectory>src</sourceDirectory>
        <plugins> <!-- plugins executes the testng tests -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19.1</version>
                <configuration>
                    <systemPropertyVariables>
                        <AppName>XYX</AppName>
                        <browserName>chrome</browserName>
                        <isLocal>true</isLocal>
                    </systemPropertyVariables>
                    <!-- Suite testng xml file to consider for test execution -->
                    <suiteXmlFiles>
                        <suiteXmlFile>${suiteFile}</suiteXmlFile>
                    </suiteXmlFiles>
                    <groups>${chooseGroup}</groups>
                    <includes>
                        <include>**.java</include>
                    </includes>
                    <testFailureIgnore>true</testFailureIgnore>
                    <argLine>
                        -javaagent:${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar
                    </argLine>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjweaver</artifactId>
                        <version>${aspectj.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
            <!-- Compiler plugin configures the java version to be usedfor compiling the code -->

        </plugins>
    </build>
</project>

It doesnt matter if its jenkins or local build.

You have to specify you test in the following way:

mvn -Dtest=TestClass#testmethod test

You forgot about that #.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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