I am writing tests for SpringBoot application. I would like to separate integration tests from unit tests. Now my project structure looks something like this:
├── Demo
│ ├── src
│ │ ├── main
| | | └──java
│ │ ├── test
| | | └──java
Is there a way to add a module like this:
├── Demo
│ ├── src
│ │ ├── main
| | | └──java
│ │ ├── integrationTest
| | | └──java
│ │ ├── test
| | | └──java
I would like that new integrationTest module to act the same as test module, but I don't know how to configure it. I managed to add it as module, mark integrationTest/java dir as Test Sources Root and run test in it but @SpringBootTest cannot resolve ApplicationContext, and all of my beans are always null.
When I write the same test in test module, it works fine.
Is there a way to do this? Is this the right way to separate integration tests? If not, what is the best practice?
I am working in intelliJ and I am using gradle as package manager.
systemProperty("spring.profiles.active", "integration"), although I guess you don't really need to if the integration and unit tests sources are separated. Credit to <baeldung.com/spring-profiles> for mentioning the system property to set. - iboisver