简体   繁体   English

多模块项目中测试类的正确位置是什么?

[英]What is the proper location for test classes in a multi module project?

Here is my overall goal: I want a Spring Boot REST API. 这是我的总体目标:我想要一个Spring Boot REST API。 Ultimately, this will have an Angular front end. 最终,它将具有Angular前端。 The REST API will have a number of JPA Entities. REST API将具有许多JPA实体。 I need to be able to use those entities in a Jasper Reports Server as well as my REST API. 我需要能够在Jasper Reports Server和REST API中使用这些实体。 To do that, I'm thinking that the best approach is a multi-module Maven project. 为此,我认为最好的方法是多模块Maven项目。 My setup would then look like this: 我的设置将如下所示:

- Project
--Web App
--Utilities
--HumanResources
--Sales
--etc.

where Web App, Utilities, HumanResources, Sales, etc. are modules. 其中Web应用程序,实用程序,HumanResources,销售等是模块。 I can use Utilities in the Web App, but the build will also produce a separate jar that I can use in Jasper (at least that is my hope). 我可以在Web App中使用实用程序,但是该构建还将产生一个可以在Jasper中使用的单独的jar(至少这是我的希望)。

Ideally, I would like to have only one application.properties file for Spring Boot. 理想情况下,我只希望有一个用于Spring Boot的application.properties文件。 However, as far as I can see, if I put the application.properties file in the Web App module, then all my unit tests (at least anything requiring a database connection) for Utilities, Sales, etc. would need to be in Web App. 但是,据我所知,如果我将application.properties文件放在Web App模块中,那么我对实用程序,销售等的所有单元测试(至少需要进行数据库连接的所有测试)都必须在Web中应用。 That doesn't seem ideal either, but if I put all the tests in their own module, it seems that I will need an application.properties file in each module, which also seems confusing. 这似乎也不理想,但是如果我将所有测试放在各自的模块中,则似乎每个模块中都需要一个application.properties文件,这似乎也令人困惑。

Is my approach valid, or is there a better way? 我的方法有效吗,还是有更好的方法? How can I do testing on each module but still have everything tied together in an easy way? 我如何在每个模块上进行测试,但仍然可以轻松地将所有内容捆绑在一起?

Thanks! 谢谢!

First of all, each module should have its own test classes in order to keep the test classes within the same module of the code tested by them. 首先,每个模块应具有自己的测试类,以将测试类保留在它们所测试的代码的同一模块内。 It would be a really bad idea to have the test classes in another module. 将测试类放在另一个模块中将是一个非常糟糕的主意。 In fact, what happens if you modify something in a module that breaks the tests but you forgot in which module the test classes were placed? 实际上,如果您修改了破坏测试的模块中的某些内容却忘记了将测试类放在哪个模块中,将会发生什么? You won't have any notification at compile time unless you compile the other module(s). 除非您编译其他模块,否则在编译时您将没有任何通知。

Second, if you need to have common configurations/files/classes, you can put all them in a common module that will hold everything that needs to be shared between the modules without duplicating them. 其次,如果您需要通用的配置/文件/类,则可以将它们全部放在一个通用模块中,该模块将保存需要在模块之间共享的所有内容,而无需复制它们。 Therefore each module will declare the common module as a dependency. 因此,每个模块都将公共模块声明为依赖项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 常用模型和工具的正确位置,用于使用 spring-boot 的多模块 Maven 项目 - Proper location for common models and utils, for multi-module maven project using spring-boot 在Java Spring / Hibernate / Maven项目中测试多步骤过程的正确方法是什么? - What is the proper way to test a multi-step process in a Java Spring/Hibernate/Maven project? 在多模块Maven项目中的模块之间共享src / test类 - Sharing src/test classes between modules in a multi-module maven project 在多模块多数据源项目中,指示将哪个数据源注入我的 DAO 的正确方法是什么? - What is the proper way to indicate which data source to inject into my DAOs in a multi-module multi-datasource project? 多模块Maven项目中共享集成测试 - Sharing integration test in multi module Maven project 在多模块maven项目的maven测试构建期间忽略模块 - Ignore a module during maven test build for multi module maven project Maven:在多模块Maven项目中生成的classes文件夹为空 - Maven: classes folder generated in multi-module maven project is empty 未使用的类未打包在 Maven 多模块项目中 - Unused classes not packaged in a Maven multi-module project 在Maven多模块项目的JUnit测试中找不到资源 - Unable to find resource in JUnit test in Maven multi-module project Java9多模块Maven项目测试依赖项 - Java9 Multi-Module Maven Project Test Dependencies
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM