【单元测试】使用Gradle运行@SpringBootTest单元测试提示“No tests found for given includes。。。 “解决

问题:
在IntelliJ IDEA中运行Gradle服务的单元测试时报错

错误提示:

Task :test FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ‘:test’.
No tests found for given includes: [DemoTest.queryString](filter.includeTestsMatching)

单元测试代码如下:

@SpringBootTest
class DemoTest{
	@Autowired
	lateinit var redisTemplate: RedisTemplate<String, String>

	@Test
    fun queryString() {
        val result = redisTemplate.opsForHash<String, String>().get("mykey", "1")
        println(result)
    }
}

依赖如下:

testImplementation("org.springframework.boot:spring-boot-starter-test:2.3.2.RELEASE")

gradle设置如下:


tasks.withType<Test> {
    enabled = true
}

解决办法:
按以下步骤设置:

  • 点击File > Setting (Ctrl+Alt+S)
  • 找到Build, Execution, Deployment > Build Tools > gradle
  • 将Run Tests using改为Intellij IDEA

当前文章作为问题记录,方便日后查询

你可能感兴趣的:(问题记录,单元测试,log4j,unit,testing,java,kotlin,gradle)