SonarQube没有进行单元测试

时间:2019-03-13 19:17:53

标签: java unit-testing sonarqube code-coverage

我有以下单元测试,涉及捕获与传入的无效bean相关的异常:

/**
     * Test scenario where someone could enter value 
     * in commandBeanName that does not exist.
     * This will throw MwsException.
     */
    @Test(expected=MwsException.class)
    public void testCommandBeanNotFound() {

        WritebackCommandMetadata writebackCommand = new WritebackCommandMetadata();
        writebackCommand.setCommandBeanName("InvalidBean");
        writebackCommand.setCommandName("Testing Invalid Bean");
        List<WritebackCommandMetadata> commands = new ArrayList<WritebackCommandMetadata>();
        commands.add(writebackCommand);

        when(configService.getCommands(any())).thenReturn(commands);
        WritebackConfigKey configKey = new WritebackConfigKey(EvaluationTypeEnum.FINAL, WritebackType.NOWORKOUT);
        beanResolver.getCommands(configKey);
    }

当我运行它时,我可以清楚地浏览代码,看到它正在捕获NoSuchBeanDefinitionException并抛出我的自定义异常。

但是,SonarQube说我对该代码块的覆盖率为0%: enter image description here

0 个答案:

没有答案