0

@RunWith(SpringRunner.class) @Runwith(PowerMockRunner.class)

How can I merge these two annotation. As RunWith only supports single value.

Souvik
  • 23
  • 1
  • 4
  • https://stackoverflow.com/a/44575071 – Gábor Bakos Jan 08 '20 at 06:37
  • Welcome to stack overflow! Unfortunately, this question is not detailed enough to give you any meaningful help. Please edit your question to include a minimal reproducible example for the issue, including sample input, preferred output, and code for what you've tried so far. – E. Zeytinci Jan 08 '20 at 06:41

1 Answers1

0

If your are working with JUnit 5 you can't use it since PowerMock doesn't support it yet.

With JUnit 4 use @Runwith(PowerMockRunner.class) and add SpringRunner.class using @PowerMockRunnerDelegate annotation. e.g.

    import org.springframework.test.context.junit4.SpringRunner; 
    import org.powermock.modules.junit4.PowerMockRunner;
    import org.powermock.modules.junit4.PowerMockRunnerDelegate;

    @RunWith(PowerMockRunner.class)
    @PowerMockRunnerDelegate(SpringRunner.class)
    @PrepareForTest(LogHelper.class)
    @WebMvcTest(controllers = UserController.class)
    public class UserControllerTest {

        @Autowired
        private MockMvc mockMvc;

        @Mock
        private UserService userService;

        @Test
        public void saveShouldReturnOK() {
            mockStatic(LogHelper.class);
            doNothing().when(LogHelper.info(anyString()));
            ....
        }
    } 
eHayik
  • 2,981
  • 1
  • 21
  • 33