0

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?

AKIWEB
  • 19,008
  • 67
  • 180
  • 294

1 Answers1

0

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.

aljipa
  • 716
  • 4
  • 6
  • @alijipa: Thanks for suggestion. I already have `logDebug(null) ` test in my question. Still it doesn't get covered all. – AKIWEB Apr 19 '14 at 14:01
  • No, I mean test with null before isDebugEnabled=false as in your case. In either case try using another tool just to make sure that you are really missing something and this is not due to external problem (cached binaries, cached report files, etc.). – aljipa Apr 19 '14 at 14:03
  • Actually, I need to use cobertura only as that's what we are following. :( – AKIWEB Apr 19 '14 at 14:04
  • Please check my answer one more time. I think the problem is as I've mentioned because you do not test logDebug() while having isDebugEnabled=true and objects=null - you only test objects=null with isDebugEnabled=false. – aljipa Apr 19 '14 at 17:16