Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Java JUnit中结合这两种RunWith?_Java_Junit_Powermock - Fatal编程技术网

如何在Java JUnit中结合这两种RunWith?

如何在Java JUnit中结合这两种RunWith?,java,junit,powermock,Java,Junit,Powermock,@RunWith(SpringRunner.class) @Runwith(PowerMockRunner.class) 如何合并这两个注释。因为RunWith只支持单值。如果您使用的是JUnit 5,您就不能使用它,因为PowerMock还没有 对于JUnit4,使用@Runwith(PowerMockRunner.class)并使用@powermockrunnerregate注释添加SpringRunner.class。e、 g import org.springframework.test

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

如何合并这两个注释。因为RunWith只支持单值。

如果您使用的是JUnit 5,您就不能使用它,因为PowerMock还没有

对于JUnit4,使用
@Runwith(PowerMockRunner.class)
并使用
@powermockrunnerregate
注释添加
SpringRunner.class
。e、 g

import org.springframework.test.context.junit4.SpringRunner;
导入org.powermock.modules.junit4.PowerMockRunner;
导入org.powermock.modules.junit4.powermockrunnerregate;
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(SpringRunner.class)
@PrepareForTest(LogHelper.class)
@WebMvcTest(controllers=UserController.class)
公共类UserControllerTest{
@自动连线
私有MockMvc-MockMvc;
@嘲弄
私人用户服务;
@试验
public void saveShouldReturnOK(){
mockStatic(LogHelper.class);
doNothing().when(LogHelper.info(anyString());
....
}
} 

欢迎使用堆栈溢出!不幸的是,这个问题不够详细,无法为您提供任何有意义的帮助。请编辑您的问题,以包含问题的最小可复制示例,包括样本输入、首选输出和您迄今为止尝试的代码。