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

Run a test with a particular maven profile #1635

Open
ramoh opened this issue Dec 2, 2023 · 9 comments
Open

Run a test with a particular maven profile #1635

ramoh opened this issue Dec 2, 2023 · 9 comments

Comments

@ramoh
Copy link

ramoh commented Dec 2, 2023

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

@jdneo
Copy link
Member

jdneo commented Dec 3, 2023

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.

@jdneo jdneo added the question label Dec 3, 2023
@ramoh
Copy link
Author

ramoh commented Dec 4, 2023

Thank you @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?

@jdneo
Copy link
Member

jdneo commented Dec 4, 2023

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?

@ramoh
Copy link
Author

ramoh commented Dec 4, 2023

@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.

@jdneo
Copy link
Member

jdneo commented Dec 5, 2023

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.

@jdneo jdneo added enhancement and removed question labels Dec 5, 2023
@ramoh
Copy link
Author

ramoh commented Dec 5, 2023

Hi @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>

@jdneo
Copy link
Member

jdneo commented Dec 5, 2023

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.

@ramoh
Copy link
Author

ramoh commented Dec 5, 2023

@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.

@jdneo
Copy link
Member

jdneo commented Dec 6, 2023

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.

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

No branches or pull requests

2 participants