Extract shared test fixtures into non-published module#755
Conversation
- Add new module `dynamic-datasource-test-fixtures` with shared service classes (UserService, StudentService, TeacherService, SchoolService, OrderService, AccountService, ProductService) and model classes - Move SQL scripts (add-remove-datasource.sql, ds-with-transactional.sql, spring-expression-language.sql) to the shared module - Configure the new module to NOT be published (disable all publishing tasks) - Update all starter modules to depend on test-fixtures and use shared fixtures - Keep UserController in each starter due to javax.servlet vs jakarta.servlet API differences - Remove duplicate test fixture code from each starter module Co-authored-by: huayanYu <16700837+huayanYu@users.noreply.github.com>
|
@copilot 包名再重构下,比如dynamic-datasource-test-common。 不需要fixture相关描述和字段出现 |
…fixture references - Renamed module from dynamic-datasource-test-fixtures to dynamic-datasource-test-common - Changed package from com.baomidou.dynamic.datasource.fixture to com.baomidou.dynamic.datasource.common - Updated all imports and scanBasePackages in test classes - Updated build.gradle comments to remove fixture terminology Co-authored-by: huayanYu <16700837+huayanYu@users.noreply.github.com>
Done in commit ab07a25. Renamed module to Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
There was a problem hiding this comment.
Pull request overview
This PR successfully consolidates duplicate test code across three Spring Boot starter modules (Boot 2.x, 3.x, and 4.x) into a shared dynamic-datasource-test-common module that is excluded from Maven publication.
Key Changes
- Created a non-published test-common module containing 15 shared Java classes and 3 SQL scripts
- Updated all three starter modules to depend on the shared test code via
testImplementation - Refactored test packages from version-specific (
fixture.v1/v3/v4) to a common structure (common.v1/v3/v4)
Reviewed changes
Copilot reviewed 76 out of 79 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| settings.gradle | Added the new test-common module to the project |
| dynamic-datasource-test-common/build.gradle | Configured module to exclude all publishing and signing tasks |
| dynamic-datasource-test-common/src/main/resources/db/*.sql | Moved 3 SQL scripts from individual starters to shared location |
| dynamic-datasource-test-common/src/main/java/.../common/service/* | Moved 15 shared model and service classes to common package |
| dynamic-datasource-spring-boot*-starter/build.gradle | Added testImplementation dependency on test-common module |
| dynamic-datasource-spring-boot*-starter/src/test/java/.../common/v*/*.java | Refactored test classes to use shared code with updated imports and scan packages |
| dynamic-datasource-spring-boot*-starter/src/test/java/.../common/controller/UserController.java | Updated UserController with new package and imports (kept separate per version for servlet API compatibility) |
| dynamic-datasource-spring-boot*-starter/src/test/resources/db/*.sql | Removed duplicate SQL files |
| dynamic-datasource-spring-boot*-starter/src/test/resources/META-INF/native-image/*.json | Removed obsolete native-image resource configuration files |
Comments suppressed due to low confidence (4)
dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/common/controller/UserController.java:33
- The change from constructor injection to field injection with @Autowired is inconsistent with best practices. Constructor injection is preferred as it:
- Makes dependencies explicit and required
- Enables immutability by allowing fields to be final
- Makes testing easier without reflection
- Makes the code more robust by preventing null pointer exceptions
Consider reverting to the original constructor injection pattern that was used before this change.
dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/common/controller/UserController.java:33
- The change from constructor injection to field injection with @Autowired is inconsistent with best practices. Constructor injection is preferred as it:
- Makes dependencies explicit and required
- Enables immutability by allowing fields to be final
- Makes testing easier without reflection
- Makes the code more robust by preventing null pointer exceptions
Consider reverting to the original constructor injection pattern that was used before this change.
dynamic-datasource-spring-boot4-starter/src/test/java/com/baomidou/dynamic/datasource/common/controller/UserController.java:26
- The import order is inconsistent with standard Java conventions. Jakarta/javax imports should come after other imports, not in the middle. The standard convention is:
- Java standard library imports
- Third-party library imports (Spring, etc.)
- Application/project imports
- Static imports (if any)
Consider reorganizing the imports to maintain consistency with standard conventions.
dynamic-datasource-spring-boot3-starter/src/test/java/com/baomidou/dynamic/datasource/common/controller/UserController.java:26
- The import order is inconsistent with standard Java conventions. Jakarta/javax imports should come after other imports, not in the middle. The standard convention is:
- Java standard library imports
- Third-party library imports (Spring, etc.)
- Application/project imports
- Static imports (if any)
Consider reorganizing the imports to maintain consistency with standard conventions.
dynamic-datasource-test-commonfor shared test codesettings.gradleto include it in the projectbuild.gradleto NOT publish to Maven (disable all publishing tasks)Summary
This PR addresses the issue of duplicate test code across the starter modules by creating a shared
dynamic-datasource-test-commonmodule.Key Changes
New module created:
dynamic-datasource-test-commonShared code includes:
User,Student,Teacher,Account,Order,Product,PlaceOrderRequest,OrderStatusUserService,StudentService,TeacherService,SchoolService,OrderService,AccountService,ProductServiceadd-remove-datasource.sql,ds-with-transactional.sql,spring-expression-language.sqlStarter modules updated:
testImplementation(project(":dynamic-datasource-test-common"))UserControllerUserControllermust remain separate due tojavax.servlet(Boot 2.x) vsjakarta.servlet(Boot 3.x/4.x) API differencesPackage structure:
com.baomidou.dynamic.datasource.common.service.*com.baomidou.dynamic.datasource.common.v1/v3/v4Benefits
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.