Cucumber-java and TestNG

With the addition of my jersey client tests, I thought I was ready to add cucumber support to my project. I was wrong. The documentation on using Cucumber and TestNG is a bit sparse and I was getting a bit flustered on where to put the feature definition file.

It turns out that I was making a mountain out of a mole hill. If you put the feature file in the wrong place, then cucumber will tell you where it was looking.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$ mvn clean test -q -Dskip=client,browser

-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running TestSuite
Configuring TestNG with: TestNG652Configurator
No features found at [classpath:com/ideoplex/tutorial]

0 Scenarios
0 Steps
0m0.000s

Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.806 sec - in TestSuite

Results :

Tests run: 4, Failures: 0, Errors: 0, Skipped: 0

So here’s the CucumberTest implementation of AbstractTestNGCucumberTests that does the work.

1
2
3
4
5
6
7
8
9
10
11
package com.ideoplex.tutorial;


import cucumber.api.CucumberOptions;
import cucumber.api.testng.AbstractTestNGCucumberTests;

@CucumberOptions(plugin = {"json:target/cucumber-report.json",
"html:target/cucumber-report"})
public class CucumberTest extends AbstractTestNGCucumberTests
{

}

Here’s the feature file, placed in src/test/resources/com/ideoplex/tutorial to match the package path of CucumberTest.

1
2
3
4
5
6
7
8
9
10
11
12
13
Feature: User Management

Scenario: Add New Email
Given prospective user with email "user@example.com" pre-exists
And email "user@example.com" is not pre-registered
When user submits add "user@example.com" form
Then email "user@example.com" is registered

Scenario: Reject Duplicate Email
Given prospective user with email "user@example.com" pre-exists
And email "user@example.com" is pre-registered
When user submits add "user@example.com" form
Then duplicate email "user@example.com" error is thrown

And the updates to the pom.xml to include the cucumber dependencies.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<version>${jersey.client.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>info.cukes</groupId>
+ <artifactId>cucumber-java</artifactId>
+ <version>${cukes.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>info.cukes</groupId>
+ <artifactId>cucumber-testng</artifactId>
+ <version>${cukes.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<properties>
<jersey.version>2.12</jersey.version>
@@ -138,6 +150,7 @@
<testng.version>6.9.4</testng.version>
<selenium.version>2.45.0</selenium.version>
<surefire.version>2.18.1</surefire.version>
+ <cukes.version>1.2.4</cukes.version>
<skip></skip>
</properties>
</project>

This version of Jersey, Gson and DataTables is on my github work branch. Normally I link to the master branch, but this feature is still half baked.

01 Nov Jersey Client with Gson