@RunWith(SpringRunner.class) @Runwith(PowerMockRunner.class)
How can I merge these two annotation. As RunWith only supports single value.
@RunWith(SpringRunner.class) @Runwith(PowerMockRunner.class)
How can I merge these two annotation. As RunWith only supports single value.
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()));
....
}
}