SonarCloud 在 Springboot 的 contextLoads 单元测试中获得 "Blocker"
SonarCloud raising a "Blocker" on Springboot's contextLoads unit test
在构建 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(){}
}
如何解决这个问题?
我进行了研究并找到了进行测试 运行 并满足 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)
在构建 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(){}
}
如何解决这个问题?
我进行了研究并找到了进行测试 运行 并满足 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)