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

Assign @SystemProperty to class / nested class and inherit on all test methods #297

Closed
JWT007 opened this issue Nov 2, 2022 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@JWT007
Copy link

JWT007 commented Nov 2, 2022

Is your feature request related to a problem? Please describe.

The example below is maybe an edge case, but I still think there is potential in the requested feature. :)

We are using the maven-git-versioning-extension in our Git project at the root to set the POM version based on branch name.
(adding extension in ".mvn/extensions.xml" and associated ".mvn/maven-git-versioning-extension.xml".)

Unfortunately, this is also picked up within the integration tests by default.

So for example, if we want to test that the version of a modified POM is "1.2.3-SNAPSHOT" it is changed to "1.2.3-hotfix-SNAPSHOT".

I have workarounds now by defining the following on every single test-method.

  @MavenGoal("install")
  @MavenTest
  @SystemProperty(value = "versioning.disable", content="true") // disable maven-git-versioning-extension for IT tests
  public void test_001(final MavenExecutionResult result) { ... }

I tried defining this @SystemProperty annotation on the test class (and the @Nested classes); however, it does not propagate to the test methods.

Describe the solution you'd like

What would be great is to just be able to define the @SystemProperty at class-level and have it propagate to all methods (and methods in @Nested subclasses).

I am assuming that the same argument might be made for the @MavenOption annotation but that is not where I am having the problem. :)

Additional context
Sample error:

java.lang.AssertionError: [GAVP] 
Expecting:
  <["me.jwt007.maven.plugins.foobar.its",
    "foobar-bom-001",
    "1.0.1-hotfix-SNAPSHOT",
    "pom"]>
to contain exactly (and in same order):
  <["me.jwt007.maven.plugins.foobar.its", "foobar-bom-001", "1.2.3", "pom"]>
but some elements were not found:
  <["1.2.3"]>
and others were not expected:
  <["1.0.1-hotfix-SNAPSHOT"]>
@JWT007 JWT007 added the enhancement New feature or request label Nov 2, 2022
@khmarbaise
Copy link
Owner

Can you create an example project which shows the wrong behaviour? Apart from that it sounds like a bug...

@JWT007
Copy link
Author

JWT007 commented Nov 2, 2022

I can try :)

@JWT007
Copy link
Author

JWT007 commented Nov 2, 2022

Hallo KH,

here is an example project:

https://github.com/JWT007/maven-it-extension-297

See the README for details:

The concrete problem is defining @SystemProperty on the outer class does not propagate to nested classes:

@DisplayName("HelloMojo:")
@MavenJupiterExtension
@MavenRepository
@SystemProperty(value = "versioning.disable", content="true") // disable maven-git-versioning-extension for IT tests
public class HelloMojo1IT {

  @Nested
  @DisplayName("Nested:")
  class NestedClass {

    @DisplayName("... test version")
    @MavenGoal("compile")
    @MavenTest
    public void test_001(MavenExecutionResult result) {...}

mvn-arguments.log

C:\JWT\SOFTWARE\apache-maven-3.8.6\bin\mvn.cmd
-Dmaven.repo.local=C:\JWT\PRJ\PWC\REPO\maven-it-extension-297\target\maven-it\me\jwt007\maven\plugins\ite\issue297\its\HelloMojo1IT\.m2\repository
--batch-mode
-V
--errors

@khmarbaise khmarbaise added bug Something isn't working and removed enhancement New feature or request labels Nov 5, 2022
@khmarbaise khmarbaise self-assigned this Nov 11, 2022
@khmarbaise khmarbaise added this to the 0.12.0 milestone Nov 11, 2022
khmarbaise added a commit that referenced this issue Nov 11, 2022
khmarbaise added a commit that referenced this issue Nov 14, 2022
@JWT007
Copy link
Author

JWT007 commented Nov 19, 2022

Thx KH, I will give it a try :) Cheers, - Jeff

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants