在为spring引导做贡献时,如何运行单元测试?

在为spring引导做贡献时,如何运行单元测试?,spring,spring-boot,unit-testing,Spring,Spring Boot,Unit Testing,在为spring boot做贡献时,我想运行一个单元测试,比如说org.springframework.boot.actuate.endpoint.EndpointIdTests 因此,我分叉并克隆了spring引导存储库,并尝试了/gradlew test--tests org.springframework.boot.actuate.endpoint.EndpointIdTests和/gradlew test--tests EndpointIdTests,但对于我得到的更长的命令: >

在为spring boot做贡献时,我想运行一个单元测试,比如说
org.springframework.boot.actuate.endpoint.EndpointIdTests

因此,我分叉并克隆了spring引导存储库,并尝试了
/gradlew test--tests org.springframework.boot.actuate.endpoint.EndpointIdTests
/gradlew test--tests EndpointIdTests
,但对于我得到的更长的命令:

> Task :spring-boot-project:spring-boot:test FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':spring-boot-project:spring-boot:test'.
> No tests found for given includes: [org.springframework.boot.actuate.endpoint.EndpointIdTests](--tests filter)
(较短命令的结果类似。)

有没有一种简单的方法可以从命令行执行此操作,或者我需要了解gradle是如何工作的

提前感谢。

秘密在于,“test”子命令需要从相关的spring引导模块目录运行,而不是从项目根目录运行

那么比如说,

cd spring-boot-project/spring-boot-actuator
../../gradlew test --tests EndpointIdTests
或更好,包括“检查”以运行检查样式:

cd spring-boot-project/spring-boot-actuator
../../gradlew check test --tests EndpointIdTests
这个答案是基于Stéphane Nicoll提供的见解