[JVM] Surefire report generating with Cucumber and maven

2,730 views
Skip to first unread message

Reddy

unread,
Jun 18, 2013, 4:58:30 AM6/18/13
to cu...@googlegroups.com
Hi All,


Iam new to cucumber struggling to generate report managed to run the test

using this ,can somebody please guide me how to generate and report using surefire


<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.app</groupId>
  <artifactId>Jink</artifactId>
  <version>1.0-SNAPSHOT</version>
  <name>Cucumber-test</name>
  <packaging>pom</packaging>
  <url>http://maven.apache.org</url>

<properties>
        <cucumber-jvm.version>1.1.2</cucumber-jvm.version>
        <selenium.version>2.32.0</selenium.version>
        <junit.version>4.10</junit.version>
        <timestamp>${maven.build.timestamp}</timestamp>
        <maven.build.timestamp.format>yyyy-MM-dd HH:mm</maven.build.timestamp.format>
</properties>
<build>
<plugins>

        <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-site-plugin</artifactId>
        <version>3.0-beta-3</version>
    </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-report-plugin</artifactId>
            <version>2.15</version>
    </plugin>
        <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>surefire-report-maven-plugin</artifactId>
                <version>2.15</version>
    </plugin>
    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.2.1</version>
    <executions>
    <execution>
        <phase>integration-test</phase>
    <goals>
        <goal>java</goal>
    </goals>
    </execution>
    </executions>
    <configuration>
        <mkdir dir="Report/Report-${timestamp}"/>
    <executableDependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-core</artifactId>
    </executableDependency>
   
<mainClass>cucumber.api.cli.Main</mainClass>
<arguments>
    <argument>--format</argument>
    <argument>junit:Report/Report-${timestamp}/cucumber-junit-report/allcukes.xml</argument>
    <argument>--format</argument>
    <argument>pretty</argument>
    <argument>--format</argument>
    <argument>html:Report/Report-${timestamp}/cucumber-html-report</argument>
        <argument>--glue</argument>
    <argument>com.app</argument>
    <argument>src/main/resources</argument>
        </arguments>

</configuration>

<dependencies>
    <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-core</artifactId>
            <version>1.1.2</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        </dependency>
</dependencies>

    </plugin>
</plugins>

 </build>
  <dependencies>
       <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-picocontainer</artifactId>
            <version>${cucumber-jvm.version}</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>${cucumber-jvm.version}</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>${selenium.version}</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-support</artifactId>
            <version>${selenium.version}</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.10</version>
        </dependency>
    <dependency>
         <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.1.1</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.14</version>
    </dependency>
    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
                <version>1.1.1</version>
       </dependency>
    <dependency>
    <groupId>info.cukes</groupId>
    <artifactId>gherkin</artifactId>
    <version>2.11.5</version>
   </dependency>
   </dependencies>

<reporting>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-report-plugin</artifactId>
        <version>2.15</version>
        </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-site-plugin</artifactId>
        <version>3.0-beta-3</version>
        </plugin>
      <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jxr-maven-plugin</artifactId>
        </plugin>
    </plugins>
  </reporting>
</project>

aslak hellesoy

unread,
Jun 18, 2013, 9:20:30 AM6/18/13
to cu...@googlegroups.com


On Tuesday, June 18, 2013, Reddy wrote:
Hi All,


Iam new to cucumber struggling to generate report managed to run the test

using this ,can somebody please guide me how to generate and report using surefire

Check out the java-helloworld example. I believe it generates a surefire report since it uses the junit runner.

Aslak 
--
-- Rules --
 
1) Please prefix the subject with [Ruby], [JVM] or [JS].
2) Please use interleaved answers http://en.wikipedia.org/wiki/Posting_style#Interleaved_style
3) If you have a question, don't reply to an existing message. Start a new topic instead.
 
You received this message because you are subscribed to the Google Groups Cukes group. To post to this group, send email to cu...@googlegroups.com. To unsubscribe from this group, send email to cukes+un...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/cukes?hl=en
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reddy

unread,
Jun 19, 2013, 4:33:44 AM6/19/13
to cu...@googlegroups.com
Thank you for replying


But not able to figure out with java-helloworld example ....can u pls share working example which would help generating reports either in surefire-report or surefire-report:report-only

Reddy

unread,
Jun 19, 2013, 6:13:43 AM6/19/13
to cu...@googlegroups.com
I have changed my pom.xml to this

and when i run mvn test----it builds  but doesnt run tests



<build>
<plugins>
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.5.1</version>
    <configuration>
    <encoding>UTF-8</encoding>
    <source>1.6</source>
    <target>1.6</target>
    </configuration>

    </plugin>
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.14</version>
    <configuration>
    <includes>
    <include>**/RunTest.java</include>
         </includes>
    </configuration>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.14</version>
    </dependency>
           
</dependencies>
<repositories>
    <repository>
    <id>codehaus</id>
    <url>http://repository.codehaus.org</url>
    </repository>
    <repository>
    <id>cukes</id>
    <url>http://cukes.info/maven</url>
    </repository>
</repositories>
</project>




On Tuesday, 18 June 2013 09:58:30 UTC+1, Reddy wrote:

Björn Rasmusson

unread,
Jun 19, 2013, 7:39:36 AM6/19/13
to cu...@googlegroups.com

This should make maven-surefire-plugin pick up and run the RunTest class file during test (since the maven-surefire-plugin by default pick up **/*Test class files and run them, the include should not really be necessary)

When you say mvn test doesn't run test, does it mean the this is printed:
[INFO] --- maven-surefire-plugin:2.14:test (default-test) ...

but not this:
--------------------------------
 T E S T S
--------------------------------
Running <package>.RunTest
...

Which indicate that the maven-surefire-plugin is not finding the RunTest class file,
or it this also printed, but RunTest is not running the cucumber test (which the @RunWith(Cucumber.class) annotation should make it do)?

Regards
Björn

Reddy

unread,
Jun 19, 2013, 8:55:04 AM6/19/13
to cu...@googlegroups.com
thanks for replying



[INFO] Scanning for projects...
[INFO]                                                                        
[INFO] ------------------------------------------------------------------------
[INFO] Building Jink 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.3:resources (default-resources) @ Jink ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 4 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ Jink ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.3:testResources (default-testResources) @ Jink ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/cq-developer/target/checkout/Jink/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ Jink ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.14:test (default-test) @ Jink ---
[INFO] No tests to run.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------



And this is my RunTest.java

import org.junit.runner.RunWith;

import cucumber.api.junit.Cucumber;

//this is a cucumber annotation dictating the cucumber runner
@RunWith(Cucumber.class)
//this is how we want the results formatted. The only customizable line, different formats can be added or removed. I’ve included the most common ones for convenience
@Cucumber.Options(format = {"pretty", "html:Report/cucumber-html-report", "json-pretty:Report/cucumber-report.json"})
//this is an empty class to run with. This needs to remain empty
public class RunTest {

Björn Rasmusson

unread,
Jun 19, 2013, 10:17:10 AM6/19/13
to cu...@googlegroups.com
when I run mvn test on the java hello world project in Cucumber-JVM I get a listing like:
...
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ java-helloworld ---
[INFO] Nothing to compile - all classes up to date
[INFO]
[INFO] --- maven-surefire-plugin: ... etc.

The problem seems to be that maven does not pick up RunTest.java as a test class and compile it in the testCompile phase.
The default place for java test classes for maven is:
src/test/java/<package-path>/

and maven places the compiled test classes by default in:
target/test-classes/<package-path>/

See if you can move RunTest so that maven report that it is compiled during testCompile and the class file put under target/test-classes (or if a remember correctly the default place for test source files can be overridden by defining the $testDirectory variable in the pom).

The it should be picked up and executed by the maven-surefire-plugin during test.



And this is my RunTest.java

import org.junit.runner.RunWith;

import cucumber.api.junit.Cucumber;

//this is a cucumber annotation dictating the cucumber runner
@RunWith(Cucumber.class)
//this is how we want the results formatted. The only customizable line, different formats can be added or removed. I’ve included the most common ones for convenience
@Cucumber.Options(format = {"pretty", "html:Report/cucumber-html-report", "json-pretty:Report/cucumber-report.json"})
//this is an empty class to run with. This needs to remain empty
public class RunTest {
}

In Cucumber-JVM 1.1.3 the "pretty" formatter has a problem which triggers an exception, the "progress" formatter is currently a safer choice.

Regerds
Björn
 
Reply all
Reply to author
Forward
0 new messages