spring-boot - SonarCloud 在 Springboot 的 contextLoads 单元测试中引发“阻止程序”
问题描述
在构建 Springboot 的应用程序并提供 Sonar Report 时,在评估上下文负载的 Springboot 默认单元测试中会引发标记为“Blocker”的代码气味:
package nz.co.datacom.oi.processor;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
@ActiveProfiles("test")
public class ProcessorApplicationTest {
@Test
public void contextLoads(){}
}
如何解决这个问题?
解决方案
我进行了一项研究,并获得了快速运行测试并满足 Sonar 的解决方案:
package nz.co.datacom.oi.processor;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
@ActiveProfiles("test")
public class ProcessorApplicationTest {
@Test(expected = Test.None.class)
public void contextLoads(){}
}
我只是包括@Test(expected = Test.None.class)
推荐阅读
- php - Composer 抛出 PHP 致命错误:部署时未找到接口“Monolog\ResettableInterface”
- javascript - ReactJS DOMException:无法在“节点”上执行“insertBefore”
- python - 在 tensorflow 的输入中投入什么工作
- android - Koin Kotlin - 如何在 Activity 之外使用注入/获取
- java - 如何获取第二级一对多关系中所有对象的计数?[爪哇]
- sql - 当整列存储为文本时,如何在SQL中分隔数字和文本?
- php - 如何为 RabbitMQ PHP 任务创建 Docker 容器
- javascript - 无法使用 async 和 Foreach 处理 Firebase 获取的值
- javascript - 如何在使用 sinon 的包装器中调用对象时进行单元测试?
- shopify - 使用 Cart.js 和 Rivets.js 添加/删除购物车项目