【发布时间】:2021-02-09 02:22:19
【问题描述】:
implementation class have two method :
test method call by test case and inside test() i call test2() which is throw exception, now I want
to
cover this method by test case but in sonar it showing not covered by test , so how i can covered this
method:
[service implementation class][1]
public void test()throws SystemException {
LOGGER.info("Testing exception");
test2(); //not covered by test
LOGGER.info("Testing exception 2");//not covered by test
System.out.print("hi");//not covered by test
}
public void test2() throws SystemException {
LOGGER.info("Testing exception");
throw new SystemException();
}
测试用例:这是调用 service.test1() 方法的测试,但在代码覆盖率中显示不是 被测试覆盖:
@Test(expected = SystemException.class)
public void test1() throws SystemException {
service.test();
}
【问题讨论】:
标签: unit-testing mockito sonarqube junit4