There is a way by which I can run junit tests only by adding arguments to the "mvn clean install" command? Without annotate tests with @Profile.
Asked
Active
Viewed 167 times
0
-
Does this answer your question? [Using Maven, how do I run specific tests?](https://stackoverflow.com/questions/7568632/using-maven-how-do-i-run-specific-tests) – Ashish Patil Jul 22 '22 at 14:37
-
Why? What is the reason? – Thorbjørn Ravn Andersen Jul 22 '22 at 14:41
-
1Technically you can make JUnit Jupiter run on particular conditions (JRE, @Enabled* details in the junit jupiter documentation https://junit.org/junit5/docs/current/user-guide/) but the question is why would you like to do that? Furthermore where is `@Profile` coming from? Ah I assume from spring boot. It has profiles but for tests in particular for unit tests it does not make sense...please give more details ... – khmarbaise Jul 22 '22 at 14:48
-
Basically I'm using springboot, you're right and I have already an active profile ("dev"). On top of existing test I want to integrate JMH. Also JMH tests I want them to be run based on a condition. (ex: mvn clean install -Pdev -Drun=jmh) Something like this if it's possible. – 35Zoll Jul 22 '22 at 14:59
-
1Maybe tags are what you are looking for [Baeldung: Tagging and Filtering JUnit Tests](https://www.baeldung.com/junit-filtering-tests) – Timo Jul 22 '22 at 15:33
-
How about `mvn test` instead? – Dut A. Jul 25 '22 at 07:12
1 Answers
1
Yes, with Junit5 what you appear to be looking for is one or more of the following annotations: @EnabledIfSystemProperty
, @DisabledIfSystemProperty
, @EnabledIfEnvironmentVariable
, @DisabledIfEnvironmentVariable
.
Refer to the user guide for some examples: https://junit.org/junit5/docs/current/user-guide/#writing-tests-conditional-execution

user268396
- 11,576
- 2
- 31
- 26