java在自己的模块上为每个模块运行spring boot单元测试
我们正在开发一个Spring引导应用程序,其中我们使用Maven进行依赖关系管理。我们把这个项目分成几个不同的服务
我有一些疑问,希望在这里得到一些见解和答案
<modules>
<module>app</module>
<module>core</module>
<module>firstlibrary</module>
<module>firstlibraryservice</module>
<module>secondlibrary</module>
<module>secondlibraryservice</module>
</modules>
应用程序-->;波姆。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>
将项目拆分为单个模块的主要目的是提高整个系统的弹性和可伸缩性。
我们将系统划分为不同的服务,每个服务都有一个base module
和一个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.
我们现在遇到的问题是,当我们在单个模块上进行错误修复或添加功能时,我们被迫在app module上编写测试,app module可以访问其pom
maven文件中定义为依赖关系的所有其他模块
我认为我们在这里遇到了一个矛盾,因为使用微服务架构的主要原因是使我们开发和测试每个模块尽可能独立于其他模块,而不是在整个应用程序级别编写测试
现在,因为每个模块只能访问它的pom.xml
依赖项中的模块,所以我们无法在模块级清理编译每个模块或编写测试
我的问题是,如何在每个模块上运行单元测试,而不是在app
模块上编写所有测试?(可以访问所有其他模块)
我希望我能在这里得到一些答案和建议
# 1 楼答案
你的POM看起来很完美,而且很有效。请看这篇博文:
https://info.michael-simons.eu/2018/06/18/maven-use-junit-5-with-spring-boot-for-unit-and-integration-tests/
你是一样的,你的项目必须毫无问题地运行,也许问题出在项目的另一部分
您可以使用此项目并与您的项目进行比较,以找出问题:
https://github.com/GLinBoy/feader/tree/develop