Giter Site home page Giter Site logo

Comments (7)

flowt-au avatar flowt-au commented on June 21, 2024

Anyone there??? Can someone just let me know if this works or not? If not, how to workaround?
Thanks,
Murray

from quarkus-cucumber.

abuinitski avatar abuinitski commented on June 21, 2024

@flowt-au stumbled across this myself. Quickly looking at extension sources, I have a strong suspicion @BeforeAll/@AfterAll are not supported at the moment.

I will look during the weekend on how can we get it working, but no quick solution - even if I am able to get it, then PR needs to be approved, version incremented, and an update published for the extension. Hope extension authors could help me with this.

from quarkus-cucumber.

flowt-au avatar flowt-au commented on June 21, 2024

@abuinitski Thank you! Sorry for my terse previous message. I was getting frustrated fighting with my flakey tests! Apologies.

What I am looking for is two things (I think):

  1. the ability to setup and tear down the whole test environment before / after all feature files run (ie the whole test run, not for each feature file). I am using RedisGraph and want to initialise the whole graph to a known state before running any tests. As a quick workaround, an over-rideable method in CucumberQuarkusTest might work?
  2. the ability to setup / tear down on a per feature file basis. Currently for that I am using a Cucumber Background which runs for each scenario but to manage that I am setting a flag in the step def so it only runs once per feature file, not once per scenario. Cucumber itself doesn't seem to support that functionality so maybe I am transgressing the functionality.

Thanks again. It is great to be able to use Cucumber with Quarkus.

Regards,
Murray

from quarkus-cucumber.

christophd avatar christophd commented on June 21, 2024

As these are Cucumber annotations instead of adding this directly to the CucumberQuarkusTest TestRunner you should be adding those @BeforeAll/@AfterAll into a separate class living in the same package as your steps.

By default Cucumber should load all @BeforeAll/@AfterAll methods that are placed in a class in the same package as the TestRunner itself.

You can also put those classes into another package but then you need to declare the package as extra glue in the CucumberOptions.

from quarkus-cucumber.

abuinitski avatar abuinitski commented on June 21, 2024

@flowt-au I am not a contributor to this extension, just having similar problems to yours.

  1. Might that be you could look not into cucumber functionality, but into Quarkus itself? https://quarkus.io/guides/getting-started-testing#applying-interceptors-to-tests
  2. I don't think Cucumber is designed to isolate stuff per-feature. Each scenario is an isolated, and scenarios are not supposed to have a common state within one feature. There are hooks before/after step, before/after scenario, and before/after whole test run. No hooks before/after all scenarios in one feature. I did this in the past by placing a normal @After hook, and inspecting context to understand that "this was the last scenario in a feature", but I don't immediately see how it's doable with cucumber-jvm (did this in the past with cucumber for node).

from quarkus-cucumber.

flowt-au avatar flowt-au commented on June 21, 2024

@christophd: Thanks for your explanation which helped me understand the "scope". I am fairly new to Java and still have much to learn.

The reason I asked my question in the first place was even though I tried placing the @BeforeAll in one of my step files, it did not run. And, even after better understanding the scope, I still cannot make it work.

Here is a screenshot of my folder structure:
Greenshot 2022-12-03 08 25 39

My TestRunner.java file:

package org.flowt.shopping.services;

import io.quarkiverse.cucumber.CucumberOptions;
import io.quarkiverse.cucumber.CucumberQuarkusTest;
import io.quarkus.test.junit.main.QuarkusMainTest;

@QuarkusMainTest

@CucumberOptions(
  features = { "src/test/resources" },
  plugin = { "pretty", "html:target/cucumber-reports/report.html" }
)

public class TestRunner extends CucumberQuarkusTest {}

and the TestRunnerGlobal.java:

package org.flowt.shopping.services;

import io.cucumber.java.BeforeAll;
import io.quarkus.logging.Log;

public class TestRunnerGlobal {
  @BeforeAll
  public static void beforeall() {
    Log.info("============= BEFORE ALL ==============");
  }
}

My tests all pass. When I look at the Terminal log the "============= BEFORE ALL ==============" is not present. (I have removed all tests except one to ensure the Terminal output is not being truncated).

If I place the @BeforeAll in one of my running step definition files, it does not run there either.

Possibly related to this "scoping" issue is that I am also using a @ParameterType annotation which works but throws exceptions if I place it in the TestRunnerGlobal.java file.

So, here is the annotation:

  @ParameterType(value = "true|True|TRUE|false|False|FALSE")
  public Boolean booleanValue(String value) {
    return Boolean.valueOf(value);
  }

It works if it is in one of my step definition files. It can be referenced from other step files. eg:

@Then("I should get a SimpleList packet with success={booleanValue}, size={int}, data={string}, failMsg={string}") // etc

Now, if I MOVE the ParameterType to the TestRunnerGlobal.java file I get the exception:

io.cucumber.core.exception.CucumberException: Could not convert arguments for step [I should get a SimpleListItem packet with success={booleanValue}, size={int}, data={string}, failMsg={string}] defined at 'org.flowt.shopping.services.SimpleListItem.testSimpleListItemCRUD.i_should_get_a_simple_list_item_packet(java.lang.Boolean,java.lang.Integer,java.lang.String,java.lang.String)'.
        at io.cucumber.core.runner.PickleStepDefinitionMatch.couldNotConvertArguments(PickleStepDefinitionMatch.java:112)

If I REMOVE the ParameterType altogether, of course I get:

io.cucumber.cucumberexpressions.UndefinedParameterTypeException: This Cucumber Expression has a problem at column 43:

I should get a Person packet with success={booleanValue}, size={int}, data={string}, failMsg={string}

If I have it in BOTH files, I get:

io.cucumber.cucumberexpressions.DuplicateTypeNameException: There is already a parameter type with name booleanValue

So, clearly my TestRunnerGlobal.java file is being picked up but the ParameterType wont work if it is there and my @BeforeAll seems to be ignored altogether.

Any suggestions about what am I missing?

Here are my dependencies:

  <dependencies>

    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-redis-client</artifactId>
    </dependency>

    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-vertx</artifactId>
    </dependency>

    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-resteasy-reactive-jackson</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-arc</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-websockets</artifactId>
    </dependency>
    <dependency>
      <groupId>io.rest-assured</groupId>
      <artifactId>rest-assured</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>io.quarkiverse.cucumber</groupId>
      <artifactId>quarkus-cucumber</artifactId>
      <version>0.6.0</version>
    </dependency>
  </dependencies>

Thanks,
Murray

from quarkus-cucumber.

flowt-au avatar flowt-au commented on June 21, 2024

@abuinitski

2. I don't think Cucumber is designed to isolate stuff per-feature.

Yes, you are correct. Having said that, my tests are way faster and more efficient if the state of the database is maintained through all Scenarios in the one Feature file. e.g. CRUD testing. So I reset the db via the Background by running it just once per feature, then Create some records, Update them in different ways (including things that throw validation errors, etc), Read the new state to confirm the db state is now as expected, then finally Delete all the records.

The alternative is to repeat myself for each scenario example row eg to test the post-update Read I would need to create a new record, update it, then read it back, then delete it, and do that for each example row in that scenario. It just seems like a lot of repetitive code. Also, the feature file for that service has all the human-readable explanation of its Business Logic in the once place in a logical sequence and the Examples support the understanding of that logic. Anyway... that's just how I look at it. Maybe it isn't a good idea for some reason, but it is working.

I will have a look at the Interceptor examples to better understand what that offers.

Thanks again,
Murray

from quarkus-cucumber.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.