【问题标题】:SonarCloud raising a "Blocker" on Springboot's contextLoads unit testSonarCloud 在 Springboot 的 contextLoads 单元测试中引发“阻止程序”
【发布时间】:2020-10-26 01:50:51
【问题描述】:
在构建 Springboot 的应用程序并提供 Sonar 报告时,在评估上下文负载的 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(){}
}
如何解决这个问题?
【问题讨论】:
标签:
spring-boot
unit-testing
sonarqube
sonarcloud
【解决方案1】:
我进行了一项研究,并获得了快速运行测试并满足 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)