Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request/ Question: Run tests as Integration Tests #32

Open
GregJohnStewart opened this issue Feb 9, 2022 · 16 comments · May be fixed by #119
Open

Feature Request/ Question: Run tests as Integration Tests #32

GregJohnStewart opened this issue Feb 9, 2022 · 16 comments · May be fixed by #119

Comments

@GregJohnStewart
Copy link

GregJohnStewart commented Feb 9, 2022

I feel that Cucumber lends itself to integration type testing. I believe, based on observation, that the tests run by this extension are run in a 'regular' test manner.

It would be fantastic for there to be a way to configure these tests to be run in an integration context.

For Maven, I imagine it would be a matter of tweaking the pom, but unsure what it would take in Gradle

@GregJohnStewart
Copy link
Author

Bump to this, any inputs?

@stuartwdouglas
Copy link
Contributor

You will have to clarify exactly what you want to be done differently? Do you just mean having failsafe run them rather than surefire? Or do you mean actually launching the produced application and testing against it?

@GregJohnStewart
Copy link
Author

I mean the difference between @QuarkusTest and @QuarkusIntegrationTest, where the tests are run against a packaged form of the app. (I would like the option to run the Cucumber in an @QuarkusIntegrationTest context)

@GregJohnStewart
Copy link
Author

Was I clear enough? Does that make sense?

@stuartwdouglas
Copy link
Contributor

Sure, but I am very unlikely to have the time to look at something like that.

@stephan-strate
Copy link

@GregJohnStewart any progress on this topic?

I would like to get into this topic, as I think cucumber is perfect for integration tests.

@GregJohnStewart
Copy link
Author

I had some code working towards it, but never quite got it working, definitely worth taking another look at (esp with Quarkus 3), and could probably use some assistance getting over the issue I was having. @stuartwdouglas Any thoughts since it's not just me asking?

@stephan-strate
Copy link

I would also be happy to contribute. Is there maybe something in the Quarkus core that can be used as a reference to get started?

Or do you mind sharing your code?

@GregJohnStewart
Copy link
Author

https://github.com/GregJohnStewart/quarkus-cucumber

The actual code for the extension is in the runtime directory. My addition I will push shortly is the CucumberQuarkusIntegrationTest class. I don't have time at the moment but next step is trying it out and remembering why this didn't work, and adjust for it. I was going to add tests in integration-tests.

@stuartwdouglas Happen to have the command used to run these tests handy? Any other notes for testing?

@GregJohnStewart
Copy link
Author

Also thinking this would be a good opportunity to add some examples and docs

@stephan-strate
Copy link

This looks like a class loading problem.

Caused by: java.lang.IllegalStateException: Unable to locate CDIProvider
	at jakarta.enterprise.inject.spi.CDI.findAllProviders(CDI.java:139)
	at jakarta.enterprise.inject.spi.CDI.getCDIProvider(CDI.java:92)
	at jakarta.enterprise.inject.spi.CDI.current(CDI.java:65)
	at io.quarkiverse.cucumber.CucumberQuarkusBase$CdiObjectFactory.getInstance(CucumberQuarkusBase.java:170)

@turing85
Copy link

turing85 commented Jun 17, 2023

This looks like a class loading problem.

Caused by: java.lang.IllegalStateException: Unable to locate CDIProvider
	at jakarta.enterprise.inject.spi.CDI.findAllProviders(CDI.java:139)
	at jakarta.enterprise.inject.spi.CDI.getCDIProvider(CDI.java:92)
	at jakarta.enterprise.inject.spi.CDI.current(CDI.java:65)
	at io.quarkiverse.cucumber.CucumberQuarkusBase$CdiObjectFactory.getInstance(CucumberQuarkusBase.java:170)

I do not think that this is a class loading problem. In QuarkusIntegrationTests, CDI is not present. I kinda somewhat got it working by booting up Weld manually. Not sure, however, how to get weld to autodiscover the beans in test-scope.

EDIT:
Got autoweld working. It is not perfect; e.g. beans with only one constructor still need the @Inject annotation and @Singletons seem not to be recognized. But those seem minor.

turing85 added a commit to turing85/quarkus-cucumber that referenced this issue Jun 23, 2023
@turing85 turing85 linked a pull request Jun 23, 2023 that will close this issue
turing85 added a commit to turing85/quarkus-cucumber that referenced this issue Jun 23, 2023
@GregJohnStewart
Copy link
Author

@turing85 Thanks for taking point! Excited to see it in place. It is interesting CDI is called for, apparently.

@turing85
Copy link

@GregJohnStewart no problem 🙂 but as mentioned in the (updated) documentation... it's not perfect. Also, I'd like to refactor the test afterwards. I think we need multipel test modules in order to automate some testing.

@AhmedDev98
Copy link

Hello,
I am a new user to this quarkus extension (thank you for providing it by the way 👍 ), and I encountered the same issue when using QuarkusIntegrationTest annotation.
In my case, I don't need CDI for this kind of tests, so I tried to use the following solution, using the CucumberOptions annotation :

@QuarkusIntegrationTest
@CucumberOptions(objectFactory = DefaultObjectFactory.class)
public abstract class CucumberQuarkusIntegrationTest extends CucumberQuarkusTest {
}

Unfortunately, this is not working, and I looked at the code in CucumberQuarkusTest, it seems to be linked to this part of code:
(https://github.com/quarkiverse/quarkus-cucumber/blob/main/runtime/src/main/java/io/quarkiverse/cucumber/CucumberQuarkusTest.java#L107-L109)

ObjectFactory objectFactory = new CdiObjectFactory();
ObjectFactorySupplier objectFactorySupplier = () -> objectFactory;

The correction would be to

  1. Use the RuntimeOptions.objectFactory if provided, instead of always using the CdiObjectFactory.
final ObjectFactory objectFactory = runtimeOptions.getObjectFactoryClass() != null
                ? new DefaultObjectFactory().getInstance(runtimeOptions.getObjectFactoryClass())
                : new CdiObjectFactory();
  1. Add @Inherited annotation to @CucumberOptions annotation , in order to be able to create a CucumberQuarkusIntegrationTest that will hide this logic of overridden objectFactory

If you agree with this solution, I can provide a patch with changes explained

Thank you

@vsevel
Copy link

vsevel commented Aug 15, 2023

any news on this?
cc @stuartwdouglas @christophd @tisoft

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants