-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
QuarkusTestResourceLifecycleManager should be executed only when a class is annotated by @QuarkusTestResource #14823
Comments
As @geoand pointed out on the mailing list, any manager that is registered via For your use case I'd suggest to introduce a Quarkus test profile: https://quarkus.io/guides/getting-started-testing#testing_different_profiles (same article @geoand linked to in his message). |
here what I have in other SpringBoot projects
I check for easy example how to do a QuarkusTest with profile. I found this
look a little to complicated. could it be possible to have something like this basic junit
tests with @QuarkusTestResource
You have already @QuarkusTestResource available, you could use them instead of
|
The reason for the current design is that @QuarkusTest only starts Quarkus once. The test resources have to be global, so the resources are started before Quarkus starts. If you use Quarkus then Quarkus can start and stop, which is why we only allow this facility through profiles. The next release of JUnit will allow us to specify a way to sort the tests so we should be able to always run tests with the same profile in a batch to make this even better. This allows Quarkus tests to run really quickly, because we are not starting and stopping all the time, but it does impose some limitations like this. I guess we could allow ad-hoc profiles that always start/stop, however its not really something we want to encourage as it will slow things down a lot (even if you app starts in one second it does not really take many tests until all those 1s delays start adding up). |
Interesting! Do you have a link to an issue or PR for that change? |
I agree that the QuarkusTestResource scope can be really weird if one is not aware of it. We are annotating a class and suddenly it's working everywhere. You can just abstract the container's life cycle on a base class but be careful if you are running tests in parallel. |
junit-team/junit5@b3ce7ae is the new ordering support. |
@survivant it sounds like you want something like this:
This will tie the test resources to the profile, and the resources will only be started for those tests. As I mentioned earlier the reason why we don't want to allow this to be per-test without a profile is that then we need to start/stop Quarkus each time, which significantly slows down testing (I guess we could try and group all tests with the same annotation, but I would not really want to do that until we have sorting support). |
@stuartwdouglas I understand the purpose of that. I just that it wasn't expected. Maybe the guide about testing need to explain a little more that. Can I suggest an ehancement. Instead we could have this
|
If I am reading this correctly, yes |
In this case, given how often people have complained about the global nature of |
I had several integration tests using wiremock proxy classes as test resources. I didn't want to write one big wiremock proxy, since each integration test needed to stub different things. I had two separate integration tests, let's say A and B and I annotated A with When running integration test A or B separately, triggered both MyFirstWireMockProxy and MySecondWireMockProxy. Having separate test profiles which stuartwdouglas mentioned on Feb 9, 2021 and defining the testresources in the profile, solved my issue (after removing the |
I have junit tests and I have integration tests (named xxxIT). I want to launch the IT test only when the maven profile "integration-test" is active. (took that my quarkus example)
I have this in my pom.xml
in my IT test, I have to create a Kind cluster and also launch a DockerCompose with TestContainer.
I created 2 classes that implements QuarkusTestResourceLifecycleManager
and I added them into my IT test like this
That works fine for IT tests, but I found out that the juni test will start the cluster and dockercompose also even if I didn't put
in my junit tests.
my junit test look like this
The text was updated successfully, but these errors were encountered: