deltaspike-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rafael Pestano <>
Subject Deltaspike Cucumber integration
Date Mon, 05 Oct 2015 20:06:28 GMT
Hi guys,

I recently made a small PoC in TestControl module to enable cucumber tests
using deltapike,  here's an example:

    features = "src/test/resources/features/uc014.feature"
public class CucumberCDITest

    public void fakeIt() //needed by junit runner




Feature: ApplicationScoped bean test
  As a user of DeltaSpike Test Control module
  I want to inject application scoped beans
  So that I can test application scoped beans

  Scenario Outline: bean increment
    Given test bean value is set to <value>
    When bean value is incremented by 2
    Then bean value should be <result>

  Examples: examples1
  | value | result |
  | 1     | 3      |
  | 0     | 2      |
  | 10    | 12     |

public class Uc014Steps

  private ApplicationScopedTestBean testBean;

  private ApplicationScopedTestBeanClient testBeanClient;

  @Given("^test bean value is set to (\\d+)$")
  public void initBeanValue(int value) {

  @When("^bean value is incremented by (\\d+)$")
  public void incrementBeanValue(int amount) {
    this.testBeanClient.increment(amount);//will increment bean value

  @Then("^bean value should be (\\d+)$")
  public void checkBeanValue(int result) {
    Assert.assertEquals(result, this.testBean.getValue());

  public void finalCheck() {
    int value =
    int nextValue =

    if (value == 0)
      throw new IllegalStateException("new application-scoped bean
instance was created");

    if (nextValue == 1)
      throw new IllegalStateException("new application-scoped bean
instance was created");


It is working here:
<> and the changes I've made are in this

I did not created another runner, for simplicity i'm running cucumber
inside CdiTestRunner, here's relevant bits:

public void run(RunNotifier runNotifier){

if (getTestClass().getJavaClass().isAnnotationPresent(CucumberOptions.class))





public void runCucumber(RunNotifier runNotifier, TestClass testClass)
throws IOException, InitializationError
    new Cucumber(testClass.getJavaClass()).run(runNotifier);

I also needed to create an object factory
in order to make step definitions (like Uc014Steps) CDI beans. This factory
must be in package 'cucumber.runtime' otherwise Cucumber wont use it (I
think there is way to make cucumber load it from other packages but we need
to create a cucumber backend for it)

Do you think this could be incorporated in Test Control module?

If you have interest I think we need to create a separated runner and then
we can get ride of the

    public void fakeIt() //needed by junit runner


without the fake test junit runner will complain cause there is no test

I needed to declare sure-fire plugin to use a newer version
I had to upgrade junit to 4.11 because cucumber-junit depends on it


Rafael M. Pestano

Desenvolvedor Java Cia. de Processamento de Dados do Rio Grande do Sul
@realpestano <>

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message