Search code examples
web-servicesjunitweblogicjdeveloper

Uncommenting code only for junit


How can I tell JUnit to skip certain lines of source code?

Context: I'm programming a WebService which uses the weblogic.logging.LoggingHelper class to create log entries.

Calls to this class are only useful, if the code runs on a weblogic server. But I want to test the code locally, without having to uncomment the logging statements for debugging all the time.


Solution

  • In order to avoid calling the LoggingHelper, you should use mocking framework like mockito where in you can mock the weblogic.logging.LoggingHelper class and avoid calling the real method.

    LoggingHelper lh = Mockito.mock(LoggingHelper.class);
    when(lh.log(anyString()).thenReturn(...);
    

    Here is the link to the framrwork https://code.google.com/p/mockito/