Search code examples
maventestngaspectjalluremaven-failsafe-plugin

Setting up steps and attachments


I am trying to setup allure2 for our integration tests, but somethings are not going well.

The TestNG listener is working fine, since the allure-results folder is being filled up. The annotations like @Step and @Attachment do not work.

The same problems with the examples from https://github.com/allure-examples/allure-testng-example.

Important part of pom.xml:

    <dependencies> <dependency>
                <groupId>io.qameta.allure</groupId>
                <artifactId>allure-testng</artifactId>
                <version>2.0-BETA14</version>
                <scope>test</scope>
            </dependency>
<dependency>
                <groupId>org.testng</groupId>
                <artifactId>testng</artifactId>
                <version>6.9.6</version>
            </dependency>
        <dependencies>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.19.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <argLine>
                        -
                        javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
                    </argLine>
                    <groups>${groups}</groups>
                    <excludedGroups>${excludedGroups}</excludedGroups>
                    <properties>
                        <property>
                            <name>listener</name>
                            <value>
                                net.sprd.qa.webdriver.listener.ScreenshotListener,net.sprd.qa.common.listeners.TestPrinterListener,net.sprd.qa.cyo.listeners.Transformer,net.sprd.qa.common.listeners.JiraListener,net.sprd.qa.webdriver.listener.SlackListener,
                            </value>
                        </property>
                        <property>
                            <name>configfailurepolicy</name>
                            <value>continue</value>
                        </property>
                        <property>
                            <name>dataproviderthreadcount</name>
                            <value>${dataProviderthreadCount}</value>
                        </property>
                    </properties>
                    <systemPropertiesFile>
                        ${propertiesFile}
                    </systemPropertiesFile>
                    <disableXmlReport>false</disableXmlReport>
                    <reportsDirectory>target/surefire-reports</reportsDirectory>
                    <parallel>methods</parallel>
                    <threadCount>${threadCount}</threadCount>
                    <forkCount>0</forkCount>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.aspectj</groupId>
                        <artifactId>aspectjweaver</artifactId>
                        <version>${aspectj.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
            <plugin>
                <groupId>io.qameta.allure</groupId>
                <artifactId>allure-maven</artifactId>
                <version>2.8</version>
                <configuration>
                    <resultsDirectory>../allure-results</resultsDirectory>
                </configuration>
            </plugin>
        </plugins>

The jvm arguments are passed correctly AND the path is actually pointing to my aspectjweaver jar.

Questions:

  • I only see surefire plugin used in all the examples. Could this be the reason?
  • How should I debug this further?
  • Can I setup my pom differently to prevent this problem? For example load the aspectj dependency differently.

Solution

  • The problem is that argLine is not applied when forkCount is 0.

    If you really need to disable forking there is two ways to fix that problem:

    1. Configure AspectJ Weaver in MAVEN_OPTS. In that case all the maven code will be weaved, so you may need to add extra aop.xml and specify classes/packages that need to be weaved.
    2. Use AspectJ compiler plugin instead of weaver.