microsoft / vscode-java-test

Run and debug Java test cases in Visual Studio Code.
https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-test
Other
292 stars 125 forks source link

Run a test with a particular maven profile #1635

Open ramoh opened 9 months ago

ramoh commented 9 months ago

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

jdneo commented 9 months ago

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: https://github.com/redhat-developer/vscode-java/issues/1263#issuecomment-583166329

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.

ramoh commented 9 months ago

Thank you @jdneo for the reply. I followed the steps mentioned in https://github.com/redhat-developer/vscode-java/issues/1263#issuecomment-583166329 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 commented 9 months ago

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 commented 9 months ago

@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 commented 9 months ago

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.

ramoh commented 9 months ago

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 commented 9 months ago

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 commented 9 months ago

@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 commented 9 months ago

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.