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

2023-12-28 14:36:27

问题:
在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

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

文章来源:https://blog.csdn.net/zx156955/article/details/135262587
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。