Created
March 13, 2019 16:02
-
-
Save evonsdesigns/a841aeb4befa1f9ba3c8c7135a938c6f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examples; | |
import org.junit.Before; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.powermock.api.mockito.PowerMockito; | |
import org.powermock.core.classloader.annotations.PrepareForTest; | |
import org.powermock.modules.junit4.PowerMockRunner; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import static org.junit.Assert.assertEquals; | |
import static org.junit.Assert.assertNull; | |
import static org.mockito.Mockito.mock; | |
import static org.mockito.Mockito.when; | |
import static org.powermock.api.mockito.PowerMockito.mockStatic; | |
@RunWith(PowerMockRunner.class) | |
@PrepareForTest({LoggerFactory.class}) | |
public class YourClassWithLogsTest { | |
@Before | |
public void hideLogMessages() { | |
mockStatic(LoggerFactory.class); | |
Logger logger = PowerMockito.mock(Logger.class); | |
PowerMockito.when(LoggerFactory.getLogger(YourClassWithLogs.class)).thenReturn(logger); | |
} | |
@Test | |
public void testMyMethod() { | |
// ... | |
} | |
// Rest of your tests | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment