How to increase the conditional coverage using jmockit for cobertura?

怎甘沉沦 提交于 2019-12-11 19:46:31

问题


I am trying to increase the code coverage for following below method using jmockit -

Below is my method in DataLogger class for which I am trying to increase the coverage -

public void logDebug(final Object... objects) {
    if (m_logger.isDebugEnabled() && objects != null) {
        m_logger.debug(message(objects));
    }
}

And below is my isDebugEnabled -

public boolean isDebugEnabled() {
    return m_logger.isDebugEnabled();
}   

Somehow my cobertura coverage report is showing as Conditional Coverage 25% [1/4] if I run my below test.

@Test
public void testLogDebug() {
    DataLogger logger = DataLogger.getInstance(ClientTest.class);
    logger.logDebug(this);
    logger.logDebug();

    new MockUp<DataLogger>() {
        @Mock
        public boolean isDebugEnabled() {
            return true;
        }
    };

    logger.logDebug(this);

    new MockUp<DataLogger>() {
        @Mock
        public boolean isDebugEnabled() {
            return false;
        }
    };
    logger.logDebug(this);

    logger.logDebug((Object) null);
}

Is there anything else I am supposed to do?


回答1:


This one passes some Object[0] that is being created for you.

logger.logDebug();

What you may be missing here could calling

logger.logDebug(null);

when isDebugEnabled returns true - but I'm not exactly sure how Cobertura measures the coverage (using Emma myself).

I urge you to separate this into different smaller test with meaningful names and check what part of your class exactly they cover.

In either case try debugging in order to see what is happening.



来源:https://stackoverflow.com/questions/23170907/how-to-increase-the-conditional-coverage-using-jmockit-for-cobertura

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!