1

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.

Fabian
  • 1,982
  • 4
  • 25
  • 35

2 Answers2

8

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/

ashoka
  • 651
  • 6
  • 10
0

No you cannot. You have to either use a mocking framework like ashoka suggested or you have to rewrite your production code such that you can easily exchange the LoggingHelper.

Jan Schaefer
  • 1,882
  • 1
  • 18
  • 23