quarkiverse / quarkus-cucumber

Quarkus Cucumber extension
Apache License 2.0
14 stars 14 forks source link

Support for Cucumber Java 8 Lambda Definitions #84

Open Hydragyrum opened 1 year ago

Hydragyrum commented 1 year ago

Are the Java 8 style bindings supported with Quarkus-Cucumber?

When I try to define my StepDefs as such:

class ApiStepDefs : En {
  init {
    Given("A GET request to the API") {
     // code goes here
    }

    When("We execute the request to the {string} endpoint") { endpoint:String ->
      // code goes here
    }

    Then("We get a blank list as a response") {
      // more code here
    }
  }
}

The test errors out as if the stepdefs were undefined

Undefined scenarios:
classpath:com/example/features/integration/Api.feature:5 # Calling the GET the api without prior initialization returns a blank list

1 Scenarios (1 undefined)
3 Steps (2 skipped, 1 undefined)
0m0.091s

For completeness, the feature file is:

# Created by Dev at 2022-11-15
Feature: An API
  Details the API behaviour

  Scenario: Calling the GET the api without prior initialization returns a blank list
    Given A GET request to the API
    When We execute the request to the "/endpoint" endpoint
    Then We get a blank list as a response

and the Runner stub

package com.michelin.pmu.dojo.features.integration

import io.quarkiverse.cucumber.CucumberOptions
import io.quarkiverse.cucumber.CucumberQuarkusTest

@CucumberOptions(
  plugin = ["pretty", "summary", "me.jvt.cucumber.report.PrettyReports:build/reports/cucumber/integration"]
)
class RunCucumberApiTests : CucumberQuarkusTest()

The features, stepdefs and runner are all in the same package.

Hydragyrum commented 1 year ago

Addendum:

Converting to the old Cucumber StepDefs format works

class ApiStepDefs {

  @Given("A GET request to the API")
  fun a_GET_request_to_the_API() {
    // code
  }

  @When("We execute the request to the {string} endpoint")
  fun we_execute_the_request_to_the_endpoint(endpoint: String) {
    // code
  }

  @Then("We get a blank list as a response")
  fun we_get_a_blank_list_as_a_response() {
     // code
  }
}

I would like to be able to use the lambda style though, as it does slightly reduce some boilerplate.