I'm trying to apply TDD in my workflow when I'm working on Spring 5 (not Spring Boot) application, but my running tests take about 45s, which makes my development cycle quite slow. Standard unit tests are super quick, but I have one test which validates Spring context configuration - it takes over 30s on its own.
My idea is to disable this particular test every time during the development cycle and run it just from time to time - e.g. when I create a Docker image with my application/make a commit/push with changes.
So here is what I come up with so far:
Define property when docker-profile is run:
<profiles> <profile> <id>docker-build</id> <properties> <build.profile.id>docker-build</build.profile.id> </properties> <build>...</build> </profile> </profiles>
Use it in
test.properties
:app.profile=${build.profile.id}
Use
@EnabledIf
annotation in test:@TestPropertySource("classpath:test.properties") @SpringJUnitConfig( classes = MainConfiguration.class ) @EnabledIf("#{'${app.profile}' == 'docker-build'}") public class SpringConfigTest { ... }
And it doesn't seem to work - I can be wrong, but app.profile
property doesn't seem to be available when I call it in @EnabledIf
. Or maybe I took a wrong route and there is simpler way to disable this particular test - I run it as mvn test
at the moment. I would like to know why app.profile
property isn't visible for @EnabledIf
though.
Edit I've discovered I can skip the first two steps and define property in command line:
mvn -Dapp.profile=docker-build test
But not sure why I can't get property from test.properties
file