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

Add ability to run tests with different config profiles #9933

Merged
merged 1 commit into from
Jun 16, 2020

Conversation

stuartwdouglas
Copy link
Member

@stuartwdouglas stuartwdouglas commented Jun 11, 2020

I don't know if 'profile' is the correct word, as it is not really directly related to the existing profile stuff.

There is also lots more we can do with this, including per profile test resources, per profile TestContainer support, and probably more.

@boring-cyborg boring-cyborg bot added area/core area/devtools Issues/PR related to maven, gradle, platform and cli tooling/plugins area/testing labels Jun 11, 2020
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface WithProfile {
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps this should be called TestProfile?

* will have different configuration options to other tests.
*
*/
public interface QuarkusTestProfile {
Copy link
Contributor

Choose a reason for hiding this comment

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

I love the idea of having all per-test configuration under one class, really simplifies things both for users and for us :)

@stuartwdouglas stuartwdouglas marked this pull request as ready for review June 15, 2020 03:56
@stuartwdouglas
Copy link
Member Author

@geoand maybe this should be @QuarkusTest(profile=MyProfile.class) rather than a separate annotation?

@stuartwdouglas
Copy link
Member Author

Actually I guess that would interfere with non-annotation based use of the extension.

@stuartwdouglas stuartwdouglas merged commit a6c68b2 into quarkusio:master Jun 16, 2020
@stuartwdouglas stuartwdouglas added this to the 1.6.0 - master milestone Jun 16, 2020
@geoand
Copy link
Contributor

geoand commented Jun 16, 2020

I'll look into not having to re-augment the application when the same test profile is re-encountered after a different one was found.
Hopefully tomorrow

@stuartwdouglas
Copy link
Member Author

I am actually looking into it now, I just wanted to get the base feature in first.

@geoand
Copy link
Contributor

geoand commented Jun 16, 2020

Oh OK :)

That's exactly why I didn't start looking into it as well, I wanted to have the base part in first. If foe whatever reason you don't get around to it today, let me know and I'll pick it up.

@stuartwdouglas
Copy link
Member Author

I don't think this is directly possible at the moment, as we can't re-run the static init steps.

@geoand
Copy link
Contributor

geoand commented Jun 16, 2020

:(

@stuartwdouglas
Copy link
Member Author

Actually I can probably just re-use the same bytecode but stick it in a new ClassLoader.

QuarkusTestProfile profileInstance = profile.newInstance();
Map<String, String> additional = new HashMap<>(profileInstance.getConfigOverrides());
if (!profileInstance.getEnabledAlternatives().isEmpty()) {
additional.put("quarkus.arc.selected-alternatives", profileInstance.getEnabledAlternatives().stream()
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI there is also quarkus.arc.exclude-types that allows you to exclude types from discovery, i.e. ignore the specified types. And it hase the same syntax as selected alternatives: https://github.com/quarkusio/quarkus/blob/master/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ArcConfig.java#L99-L113

*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface TestProfile {
Copy link
Contributor

@knutwannheden knutwannheden Jun 26, 2020

Choose a reason for hiding this comment

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

IMHO it would make sense to define this interface as @Inherited in case someone wants to define it on a common superclass.

For JUnit 5 tests I am also used to be able to define my own composed annotations with meta-annotations, which I think could also be very useful for Quarkus' test annotations like @QuarkusTestResource and @TestProfile. But for this I will file a separate enhancement request.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please do, that sounds useful

Copy link
Contributor

Choose a reason for hiding this comment

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

See #10297.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should I file a separate enhancement request for declaring @QuarkusTestResource and @TestProfile as @Inherited?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure yeah

Copy link
Contributor

@geoand geoand Jun 26, 2020

Choose a reason for hiding this comment

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

See #10297.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/core area/devtools Issues/PR related to maven, gradle, platform and cli tooling/plugins area/documentation area/testing release/noteworthy-feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants