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

Introduce a new set of test callbacks used right before and after test execution #27019

Merged
merged 1 commit into from Aug 2, 2022

Conversation

geoand
Copy link
Contributor

@geoand geoand commented Jul 29, 2022

These callbacks essentially offer similar functionality to JUnit's
org.junit.jupiter.api.extension.BeforeTestExecutionCallback and
org.junit.jupiter.api.extension.AfterTestExecutionCallback

Closes: #26999

@Cs4r
Copy link

Cs4r commented Jul 29, 2022

Thanks for your work @geoand.

However, how can I build a jar with these changes? 😅

@geoand
Copy link
Contributor Author

geoand commented Jul 29, 2022

You can do the following:

git clone -b #26999 --single-branch git@github.com:geoand/quarkus.git
cd quarkus
mvn -Dquickly -Dformat.skip=true

Then use the following BOM:

      <dependency>
        <groupId>io.quarkus</groupId>
        <artifactId>quarkus-bom</artifactId>
        <version>999-SNAPSHOT</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>

@Cs4r
Copy link

Cs4r commented Jul 29, 2022

@geoand:

if I do a git clone -b #26999 --single-branch git@github.com:geoand/quarkus.git I get the error:

error: switch `b' requires a value

If I do a git clone -b 26999 --single-branch git@github.com:geoand/quarkus.git (without hash) I get the error:

Cloning into 'quarkus'...
warning: Could not find remote branch 26999 to clone.
fatal: Remote branch 26999 not found in upstream origin

Thanks in advance.

@geoand
Copy link
Contributor Author

geoand commented Jul 29, 2022

Can you try git clone -b '#26999' --single-branch git@github.com:geoand/quarkus.git?

@Cs4r
Copy link

Cs4r commented Aug 1, 2022

@geoand :

Apparently, this feature doesn't work yet.

I have created a simple class implementing io.quarkus.test.junit.callback.QuarkusTestBeforeTestCallback:

package cs4r;

import io.quarkus.test.junit.callback.QuarkusTestBeforeTestCallback;
import io.quarkus.test.junit.callback.QuarkusTestMethodContext;

public class MyQuarkusTestBeforeTestCallback implements QuarkusTestBeforeTestCallback {

    @Override
    public void beforeTest(QuarkusTestMethodContext context) {
        System.out.println("beforeTest");
    }
}

Then (as https://quarkus.io/guides/getting-started-testing#enrichment-via-quarkustestcallback says) I have created the file src/main/resources/META-INF/services/io.quarkus.test.junit.callback.QuarkusTestBeforeTestCallback with the following content:

cs4r.MyQuarkusTestBeforeTestCallback

but for some reason I am not aware of yet, the callback is never executed.

This is also happening with io.quarkus.test.junit.callback.QuarkusTestAfterTestCallback, therefore I reckon it might be that the algorithm for parsing the files:

  • src/main/resources/META-INF/services/io.quarkus.test.junit.callback.QuarkusTestBeforeTestCallback
  • src/main/resources/META-INF/services/io.quarkus.test.junit.callback.QuarkusTestAfterTestCallback

is missing.

@geoand
Copy link
Contributor Author

geoand commented Aug 1, 2022

Can you share the example project you used?

@geoand
Copy link
Contributor Author

geoand commented Aug 1, 2022

PR updated, it should work now (I force pushed to the branch, so best delete your local copy of it)

@Cs4r
Copy link

Cs4r commented Aug 1, 2022

@geoand this time it works like a charm 😄

Will this be added in the next release?

Thanks in advance.

@geoand
Copy link
Contributor Author

geoand commented Aug 1, 2022

Thanks a lot for checking!

It will be included in 2.12.0.CR1 onwards, but I am wondering if we can add it to 2.11.2.Final - WDYT @gsmet?

@geoand
Copy link
Contributor Author

geoand commented Aug 1, 2022

I'll finish the PR tomorrow by adding tests

@geoand geoand marked this pull request as ready for review August 2, 2022 05:08
@quarkus-bot quarkus-bot bot added this to To do in Quarkus Documentation Aug 2, 2022
@geoand geoand requested a review from gastaldi August 2, 2022 05:08
@quarkus-bot

This comment has been minimized.

Quarkus Documentation automation moved this from To do to Review pending Aug 2, 2022
Copy link
Contributor

@gastaldi gastaldi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small naming suggestion change to match the same hooks JUnit provides

@geoand
Copy link
Contributor Author

geoand commented Aug 2, 2022

Good point! Fixed

@geoand geoand requested a review from gastaldi August 2, 2022 05:32
Copy link
Contributor

@gastaldi gastaldi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing doc changes, but the rest looks okay, approved ;)

docs/src/main/asciidoc/getting-started-testing.adoc Outdated Show resolved Hide resolved
docs/src/main/asciidoc/getting-started-testing.adoc Outdated Show resolved Hide resolved
Quarkus Documentation automation moved this from Review pending to Reviewer approved Aug 2, 2022
…t execution

These callbacks essentially offer similar functionality to JUnit's
org.junit.jupiter.api.extension.BeforeTestExecutionCallback and
org.junit.jupiter.api.extension.AfterTestExecutionCallback

Closes: quarkusio#26999
@geoand
Copy link
Contributor Author

geoand commented Aug 2, 2022

I knew I would miss something :)

@gsmet gsmet merged commit f2e4c80 into quarkusio:main Aug 2, 2022
Quarkus Documentation automation moved this from Reviewer approved to Done Aug 2, 2022
@quarkus-bot quarkus-bot bot added this to the 2.12 - main milestone Aug 2, 2022
@quarkus-bot quarkus-bot bot added the kind/enhancement New feature or request label Aug 2, 2022
@gsmet
Copy link
Member

gsmet commented Aug 2, 2022

Will backport it to the next 2.11 micro.

@geoand
Copy link
Contributor Author

geoand commented Aug 2, 2022

Great, thanks!

@geoand geoand deleted the #26999 branch August 2, 2022 13:47
@gsmet gsmet modified the milestones: 2.12 - main, 2.11.2.Final Aug 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

Add QuarkusBeforeTestExecutionCallback
4 participants