Skip to content

When running JUnit tests, properties set on surefire plugin are not available #1233

Closed

Description

Setting systemProperties on the surefire plugin seems to not be available when running a test.

Project to test : github.com/konveyor/tackle-pathfinder
Class to test : AssessmentsResourceTest.java ( any test )

It will fail becayse the system property "keycloak.version" defined in a dependency of this project is not available to the test. This project depends on github.com/konveyor/tackle-commons-rest , and there in the rest-test submodule you can find class KeycloakTestResource that tries to ready that property.

Definition of the property :

    <plugins>
      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>${surefire-plugin.version}</version>
        <configuration>
          <systemPropertyVariables>
            <keycloak.version>${keycloak.version}</keycloak.version>
          </systemPropertyVariables>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-failsafe-plugin</artifactId>
        <version>${surefire-plugin.version}</version>
        <configuration>
          <systemPropertyVariables>
            <keycloak.version>${keycloak.version}</keycloak.version>
          </systemPropertyVariables>
        </configuration>
      </plugin>
    </plugins>
  </build>```

It also fails if the property is defined in the project being tested.

Activity

  1. jdneo commented on Jul 24, 2021

    @jdneo
    Member
  2. no-response commented on Aug 7, 2021

    @no-response

    This issue has been closed automatically because it needs more information and has not had recent activity. Please reach out if you have or find the answers we need so that we can investigate further.

  3. tomjenkinson commented on Jun 27, 2025

    @tomjenkinson

    I think the point that is being raised it (likely) was somehow expected that the settings in the Maven build system would be provided to the VSCode test infrastructure automatically for the test. For myself what I am finding is indeed if I create a test configuration in VSCode that I copy various properties from the pom (manually) into then I can make my own experiments work. I think the thing is, given that there is Maven integration provided (in https://github.com/redhat-developer/vscode-java) then it might be expected that VSCode would not manually need to be provided system properties by the developer that are present in the poms related to maven-surefire-plugin, and VSCode would somehow be provided with the right configuration by the Maven integrations understanding of the pom.xml(s) for the module.

    If it's not already expected to work this way, do you think that type of integration is something that could reasonably be requested as a new feature and if so, would you think that additional integration would be provided by something in https://github.com/microsoft/vscode-java-test or does it look more something that would be part of https://github.com/redhat-developer/vscode-java?

  4. mickaelistria commented on Jul 4, 2025

    @mickaelistria

    Tom Jenkinson (@tomjenkinson) I'm not sure many people read notifications on closed issues. What I suggest is that you create a new one, also sharing a minimal project to reproduce the issue.

  5. tomjenkinson commented on Jul 4, 2025

    @tomjenkinson

    Thanks for the pointer Mickael Istria (@mickaelistria) - I am still not sure if this here is even the right project to raise this. I have a discussion over in a different project too redhat-developer/vscode-java#4089. It might be that the Maven integration of Java might need the to change (rather than core Microsoft VS Code testing framework).

  6. mickaelistria commented on Jul 4, 2025

    @mickaelistria

    I think this is the right project here:

    • vscode-java takes care of computing the classpath and other compiler configuration in order to configure the project and provide the related assistance
    • vscode-java-test takes care of creating the project "launch configuration" and that includes things like system properties.

    Both can interact and some aspect, or read similar info from that same source, but basically, whenever there is something to run, vscode-java-test is most likely the right project.

  7. tomjenkinson commented on Jul 4, 2025

    @tomjenkinson

    And you would say that even if the system properties are defined in any format (in this case Maven, could be ANT or other build system) it is still just something particular to microsoft/vscode repo? I presume that the Maven integration would still need to tell vscode-java-test what properties to use and I presume that the Maven integration code is particular to redhat-developer/vscode-java?

    I am thinking there are two issues:

    1. microsoft/vscode-java-test is not persistently able to be told the system properties to use for a specific single/group of tests. I think I have experienced this tool, different configurations can be set in User settings (say) but I don't think you can say for testX always use configA and for testY always use configB - that does feel like a feature request for this repo.
    2. redhat-developer/vscode-java does not adapt the Maven format into a format of test configuration that microsoft/vscode-java-test can understand and use in the feature request outlined in step 1.
  8. mickaelistria commented on Jul 4, 2025

    @mickaelistria

    I presume that the Maven integration would still need to tell vscode-java-test what properties to use and I presume that the Maven integration code is particular to redhat-developer/vscode-java?

    This presumption is inaccurate.
    There is code in this repo that takes care of articulating the Maven integration to read some information from it:

    ; The Maven integration is not particular to vscode-java, this vscode-test-java can and does also consume the Maven integration (from Eclipse m2e project), more or less directly.

    But at this stage, before trying to find a solution or analyzing an issue or whatever; what is really missing is a small example project to reproduce the issue. When such a project is available, let's just open a new issue report with it and let maintainers take care of the analysis and resolution.

  9. tomjenkinson commented on Jul 4, 2025

    @tomjenkinson

    Thank you for finding that Mickael - I was unsure of whether the maintainers of this repo would be able to help if there was no existing Maven integration expected by this repo but that code you referenced does look like they do anticipate they should be aware of it (I should have search for Maven in this repo myself - thank you for helping me find that) and it looks more like a part (at least for not understanding test dependencies in profiles) could be reported as a bug now and a feature request could also be raised for persistently maintaining per test configurations and a feature request for per Maven module test configurations to be defined. I would like to help with raising some of these when I have some time available for it and if they are not raised in the meantime.

    Thank you very much, Mickael for helping me generally here and especially in understanding how indeed microsoft/vscode-java-test does appear to be expected to understand Maven.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions