Running spring boot unit tests for every module on their own module

Oxobo :

We are working on a Spring-boot application in which we are using Maven for dependency management. We divided the project into several modules as different services.

I have some doubts and hope to get some insights and answers here.

<modules>
    <module>app</module>
    <module>core</module>
    <module>firstlibrary</module>
    <module>firstlibraryservice</module>
    <module>secondlibrary</module>
    <module>secondlibraryservice</module>
</modules>

app -- > pom.xml

<dependencies>
    <dependency>
        <groupId>com.microservice</groupId>
        <artifactId>core</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>com.microservice</groupId>
        <artifactId>firstlibraryservice</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>com.microservice</groupId>
        <artifactId>firstlibrary</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>com.microservice</groupId>
        <artifactId>secondlibraryservice</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>com.microservice</groupId>
        <artifactId>secondlibrary</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>


    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ojdbc7</artifactId>
        <version>12.1.0.1</version>
    </dependency>


</dependencies>

The main intention of splitting the project to work on individual modules is to increase resilient and scalability of overall system. We’ve divided the system to different services, for each service we have a base module as well as a service module.

Each base module can access other services based on its needs with maven dependency but no base module is allowed to directly access other base modules.

The problem that we have encountered now is that when we do the bug fixes or adding features on a single module we are forced to write the tests on app module that has access to all other modules that are defined as dependency in its pom maven file.

I think we have encountered a contradiction here as the main cause of using microservice architecture was making us to develop and test each module as independent as possible from other modules instead of writing our tests on the entire application level.

Right now because each module has access only to modules that are in it’s pom.xml dependencies we cannot clean compile each module or write tests on module level.

My question is how can I run the unit tests for every module on their own module instead of writing all tests on app module? (which has access to all other modules)

I hope I can get some answers and suggestions here.

GLinBoy :

Your POM looks perfect and it just works. Look at this blog post:

https://info.michael-simons.eu/2018/06/18/maven-use-junit-5-with-spring-boot-for-unit-and-integration-tests/

You're the same and your project must run without problem, maybe the problem is on another part of your project.

You can use this project and compare with your project to find out the problem:

https://github.com/GLinBoy/feader/tree/develop

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=161137&siteId=1