Vinod Hejib
Vinod Hejib

Reputation: 167

mvn test does not launch Test NG tests but shows Build Successful

When running my Maven project with mvn test and testing.xml, my tests are not launched. But build shows successful. I have included necessary maven-surefire-plugin. Pls can anybody help.

The project structure

Content pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.siemens.fossology.test</groupId>
    <artifactId>ui-test</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>ui-test</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

        <main.class>com.siemens.fossology.test.ui.StartUp</main.class>

        <java.version>1.7</java.version>
        <config-builder.version>1.3.1</config-builder.version>
        <testng.version>6.1.1</testng.version>
        <guava.version>18.0</guava.version>
        <slf4j.version>1.7.7</slf4j.version>
        <logback.version>1.1.2</logback.version>
        <mockito.version>1.10.8</mockito.version>
        <hamcrest.version>1.3</hamcrest.version>
        <selenium-java.version>2.47.1</selenium-java.version>
        <xml-apis.version>1.4.01</xml-apis.version>

        <maven-compiler-plugin.version>3.3</maven-compiler-plugin.version>
        <maven-jar-plugin.version>2.5</maven-jar-plugin.version>
        <maven-assembly-plugin.version>2.4</maven-assembly-plugin.version>
        <maven-shade-plugin.version>2.3</maven-shade-plugin.version>

    </properties>

    <dependencies>
        <dependency>
            <groupId>com.tngtech.java</groupId>
            <artifactId>config-builder</artifactId>
            <version>${config-builder.version}</version>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>${testng.version}</version>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>${guava.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4j.version}</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>${logback.version}</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-core</artifactId>
            <version>${logback.version}</version>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-all</artifactId>
            <version>${hamcrest.version}</version>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>${mockito.version}</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>${selenium-java.version}</version>
        </dependency>
        <dependency>
            <groupId>xml-apis</groupId>
            <artifactId>xml-apis</artifactId>
            <version>${xml-apis.version}</version>
        </dependency>
        <!--<dependency> <groupId>org.apache.maven.surefire</groupId> <artifactId>surefire-testng</artifactId> 
            <version>2.16</version> </dependency> -->
    </dependencies>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>0.7.2.201409121644</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>prepare-agent</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>report</id>
                            <phase>prepare-package</phase>
                            <goals>
                                <goal>report</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <excludes>
                            <exclude>org/xmlsoap/schemas/**</exclude>
                            <exclude>org/apache/ws/commons/schema/**</exclude>
                        </excludes>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven-compiler-plugin.version}</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.12.4</version>
                <configuration>
                    <suiteXmlFiles>
                        <suiteXmlFile>testing.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>${maven-jar-plugin.version}</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>${main.class}</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>${maven-assembly-plugin.version}</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <mainClass>${main.class}</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>${maven-shade-plugin.version}</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>${main.class}</mainClass>
                                </transformer>
                                <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>META-INF/spring.handlers</resource>
                                </transformer>
                                <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>META-INF/spring.schemas</resource>
                                </transformer>
                                <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                    <resource>META-INF/spring.tooling</resource>
                                </transformer>
                            </transformers>
                            <shadedArtifactAttached>true</shadedArtifactAttached>
                            <shadedClassifierName>with-dependencies</shadedClassifierName>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

The testing.xml content

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "testng.org/testng-1.0.dtd">

<suite verbose="0" name="Default suite">
    <test verbose="2" name="Default test" preserve-order="false">
        <classes>
            <class name="com.siemens.fossology.test.ui.scripts.AdminCleanupTest" />
        </classes>
    </test>
</suite>

Upvotes: 2

Views: 12594

Answers (4)

Juan David Davila
Juan David Davila

Reputation: 1

Just modify each .class file name to finish with the word test.

Example:

FirstLoginTest.class

GetCustomersTest.class

Upvotes: 0

Vinod Hejib
Vinod Hejib

Reputation: 167

Changing maven-surefire-plugin version to 2.14.1 in pom.xml has solved the issue. Now my mvn test launches TestNG tests.Verhagen, juherr Thanks for the inputs. But still i dont know why it expected this version?

Upvotes: 4

question_maven_com
question_maven_com

Reputation: 2475

Move testing.xml in src/test/resources/ directory

and then change pom with:

<suiteXmlFile>src/test/resources/testing.xml</suiteXmlFile>

Upvotes: 1

Verhagen
Verhagen

Reputation: 4034

In an other project I see the doctype defined as:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

Where you have

<!DOCTYPE suite SYSTEM "testng.org/testng-1.0.dtd" >

Could that be the cause ?

Upvotes: 0

Related Questions