Skip to content

Run a test with a particular maven profile #1635

Open

Description

@ramoh

I want to run certain tests with a particular maven profile. Let me know how can i do that.

Activity

  1. jdneo commented on Dec 3, 2023

    @jdneo
    Member

    Technically, it's doable. But it's not convenient.

    The key is to let the Java Language Server import the project using the target profile. See: redhat-developer/vscode-java#1263 (comment)

    And in order to make those config files generate at the project root, you need to enable java.import.generatesMetadataFilesAtProjectRoot. Remember update this setting at WORKSPACE scope, so that it won't affect your other projects.

  2. ramoh commented on Dec 4, 2023

    @ramoh
    Author

    Thank you Sheng Chen (@jdneo) for the reply. I followed the steps mentioned in redhat-developer/vscode-java#1263 (comment) but it is not working for me. Can I look at some logs to confirm whether my Test Runner is picking up the right maven profile to execute the test?

  3. jdneo commented on Dec 4, 2023

    @jdneo
    Member

    Test Runner does not know which profile it is running towards.

    The way how it works is:

    The Java Language Server will import the maven project using m2e, which converts the Maven project to an internal project model representation. So it's the m2e needs the profile name and import it correctly. When you run a test, Test Runner ask Java Language Server for information like classpath, and run it.

    What kind of configuration are you changing in your test profile?

  4. ramoh commented on Dec 4, 2023

    @ramoh
    Author

    Sheng Chen (@jdneo) We have catergorized tests as per the enviroment and we initialize those enviroment as per the profile setting.
    For example, we have a profile for long run tests which instantiates db schema as per the test requirement. We also have enviroment variables which get set as per the profile.

  5. jdneo commented on Dec 5, 2023

    @jdneo
    Member

    I see. I'm afraid it's not supported right now. You have to manually run the long running tests. We environment variable, currently you can set it via the java.test.config setting.

  6. ramoh commented on Dec 5, 2023

    @ramoh
    Author

    Hi Sheng Chen (@jdneo) I have the following profile defined in my parent POM.xml . How can I configure this using java.test.config

    <profile>
                <id>long-tests-standalone</id>
                <activation>
                    <activeByDefault>false</activeByDefault>
                </activation>
                <properties>
                    <nr.testing.service.type>PCS</nr.testing.service.type>
                    <nr.testing.spring.profile>standalone</nr.testing.spring.profile>
                </properties>
                <build>
                    <plugins>
                        <plugin>
                            <groupId>xyz.rrr.nr</groupId>
                            <artifactId>dbschema-maven-plugin</artifactId>
                            <version>${nr.build.dbschema.plugin.version}</version>
                            <executions>
                                <execution>
                                    <goals>
                                        <goal>refresh</goal>
                                    </goals>
                                </execution>
                            </executions>
                        </plugin>
                        <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-surefire-plugin</artifactId>
                            <version>${maven.surefire.plugin.version}</version>
                            <configuration>
                                <excludedGroups>xyz.rrr.testing.junit.categories.FailingTests,xyz.rrr.testing.junit.categories.EmbeddedEnv</excludedGroups>
                                <includes>
                                    <include>${nr.testing.alltestsuite}</include>
                                </includes>
                            </configuration>
                        </plugin>
                    </plugins>
                </build>
           </profile>
    
  7. jdneo commented on Dec 5, 2023

    @jdneo
    Member

    I see. That's properties, I was thought about env variable before. Sorry for the confusion. The java.test.config does not allow to customize properties.

    BTW, Is it possible to share a minimal sample project? I would like to use that to check where is the gap.

  8. ramoh commented on Dec 5, 2023

    @ramoh
    Author

    Sheng Chen (@jdneo) I will try to put up something.
    BTW, Just assume that the properties defined above can be exported to env variables. What about other plugin goals "refresh". How can I make the test execute this goal before running the test?
    Thank you for giving the time.

  9. jdneo commented on Dec 6, 2023

    @jdneo
    Member

    How can I make the test execute this goal before running the test?

    I guess you can use the preLaunchTask: Define a task to run refresh before test execution.

  10. github-actions commented on Nov 12, 2025

    @github-actions

    Hi Rajesh Mohanty (@ramoh), I'm an AI Support assistant here to help with your issue. While the team reviews your request, I wanted to provide some possible tips and documentation that might help you in the meantime.

    To run tests under a specific Maven profile, include the -P flag when invoking Maven. For example:

    • mvn test -P my-profile

    • Or target a specific goal/plugin:
      mvn groupId:artifactId:goal -P profile-1,profile-2

    References:

    The team will respond to your issue shortly. I hope these suggestions are helpful in the meantime. If this comment helped you, please give it a 👍. If the suggestion was not helpful or incorrect, please give it a 👎. Your feedback helps us improve!

  11. kgskgs commented on Jan 21, 2026

    @kgskgs

    This is essential when running maven tests

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