JUnit5 run a unit test conditionally

I want a JUnit test to run only if I know I am running on my local dev machine and everything is prepared, E.g:

  • DB is set-up with the right data,
  • I have started other services that are called, Payment Service , etc..
  • annotate your test with `@EnableIfEnvironment`
  • Set an Environment Variable

The simplest solution I have found is to use the `HOME` env variable

@EnabledIfEnvironmentVariable(named = "HOME", matches = "/home/razvan.gaston")
public class CartCheckoutShould extends BaseIntegrationTest 

Resournces:

https://nipafx.dev/junit-5-disabled-conditions
https://www.baeldung.com/junit-5-conditional-test-execution

Leave a comment