问题
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