Allure integration with multi-module test suite

Naman :

We have an test suite which is based on maven framework and consists of multi-module. Modules used -

  • project [no code]
  • test [@Test classes are included under /src/main/java, testng.xml in /src/main/resources]
  • core [configured to execute basic utilities for environment setup]
  • driver [configures test buckets and modulates report generation using testng]

Trying to integrate the report generation using allure, I've added the following to the project pom.xml -

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${maven-surefire-plugin.version}</version>
                <configuration>
                    <testFailureIgnore>false</testFailureIgnore>
                    <argLine>
                        -javaagent:${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar
                    </argLine>
                    <properties>
                        <property>
                            <name>listener</name>
                            <value>ru.yandex.qatools.allure.junit.AllureRunListener</value>
                        </property>
                    </properties>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjweaver</artifactId>
                        <version>${aspectj.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven-compiler-plugin.version}</version>
                <configuration>
                    <source>${jdk.version}</source>
                    <target>${jdk.version}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>${maven-deploy-plugin.version}</version>
            </plugin>
            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>9.2.10.v20150310</version>
                <configuration>
                    <webAppSourceDirectory>${project.build.directory}/site/allure-maven-plugin</webAppSourceDirectory>
                    <stopKey>stop</stopKey>
                    <stopPort>1234</stopPort>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

<reporting>
    <excludeDefaults>true</excludeDefaults>
    <plugins>
        <plugin>
            <groupId>ru.yandex.qatools.allure</groupId>
            <artifactId>allure-maven-plugin</artifactId>
            <version>2.2</version>
        </plugin>
    </plugins>
</reporting>

Also the dependencies for the same to the test pom.xml as -

<!--allure related dependencies-->
        <dependency>
            <groupId>ru.yandex.qatools.allure</groupId>
            <artifactId>allure-testng-adaptor</artifactId>
            <version>1.4.16</version>
            <exclusions>
                <exclusion>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>com.github.detro.ghostdriver</groupId>
            <artifactId>phantomjsdriver</artifactId>
            <version>1.0.4</version>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-all</artifactId>
            <version>1.3</version>
        </dependency>
        <dependency>
            <groupId>ru.yandex.qatools.allure</groupId>
            <artifactId>allure-java-annotations</artifactId>
            <version>1.5.0.RC2</version>
        </dependency>

Step 1 - After executing the tests mvn exec:java -pl driver I can see a /target/allure-results folder generated.

Step 2 - mvn jetty:run reads Started Jetty Server

Step 3 - But when I go to localhost:8080 on my browser it just has a heading

Directory :/

Question

  • I doubt the path specified by me is incorrect somewhere so jetty is unable to locate the reports, but couldn't figure out where. Is it for the tests that are executed or for the testng.xml in resources? Or do I need to correct the path somewhere in the pom only?

  • Also is the way I am trying to use the dependencies(in parent project pom) correct?


Update 1

The exec configuration used is as follows -

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.5.0</version>
            <configuration>
                <mainClass>com.driver.Driver</mainClass>
            </configuration>
        </plugin>
    </plugins>
</build>

Appreciate any response.

A_Di-Matteo :

There are many open points on this question which are not clear due to lack of details.

According to your description the project structure is hence as following:

project
  |
  |--- test-module
  |--- core-module
  |--- driver-module (depends on `core` and `test`)
  |
   \ pom.xml

You actually execute tests only via the driver module and via the exec-maven-plugin, however the allure documentation specifies the classic approach, to execute the test phase, that is, the Maven phase dedicated to tests execution (via the maven-surefire-plugin, automatically invoked by Maven during this phase via default bindings).

You actually configure the maven-surefire-plugin as specified by its documentation: specifying it into the parent pom.xml file would be fine in this case, in its pluginManagement section > Maven will pick up its global configuration during the default-test execution of the default maven-surefire-plugin binding.

However, the whole mechanism is linked to the test phase. Do you execute it?

You did not provide details about the exec-maven-plugin and what it is supposed to do concerning the driver module and why you would use the jetty-maven-plugin to see the report. Normally, test reports are available and can be seen direct html files, no need to host them in an embedded jetty server, unless required by the overall process (CI, deployment to a company server, etc.). These reports should also be made available to the project documentation site, which can be generated via the site lifecycle and its maven-site-plugin.

From your details, you share the jetty-maven-plugin configuration pointing at a site folder: is this folder generated during the test phase (if you invoke it)? Or during your exec invocation?

Concerning the way you use dependencies in the parent pom, you actually did not share it in your question, so not easy to help. Normally, you would put dependencies in the dependencies section of the parent pom which are common to all modules (e.g. classic example is log4j, something every module would use). Otherwise, you would use the dependencyManagement section of the parent pom to manage versions of certain dependencies which could be use by one or more modules (but modules would need to re-declare them to effectively use them, omitting their versions though, specified by the parent). That is, the parent pom is a central place of governance and harmonisation.


Update

Concerning the /target/allure-results folder generated, you need also to check its content to be a valid site directory (that is, e.g. it should contain an index.html).

Creating a new Maven webapp project and adding the following to its pom.xml file:

<build>
    <plugins>
        <plugin>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>9.2.10.v20150310</version>
            <configuration>
                <webAppSourceDirectory>${project.build.directory}/site</webAppSourceDirectory>
                <stopKey>stop</stopKey>
                <stopPort>1234</stopPort>
            </configuration>
        </plugin>
    </plugins>
</build>

(Note: exactly as per your question, but pointing simply to the site directory)

And executing:

mvn clean install site
mvn jetty:run

the Maven site (generated during the site phase as invoked above) would be available at localhost:8080 (default jetty URL). That's because an index.html was generated.

However, if I manually delete the index.html, the jetty will show an Directory: / page, listing the available files.

Hence, most probably, the allure report didn't generate an index.html file, because most probably it is not meant to generate it, but simply an HTML report generared during the test phase.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=455232&siteId=1