Pri*_*iya 2 unit-testing mockito powermock junit5 junit-jupiter
我有一个示例测试类,我想在其中模拟一个静态类。我的 build.gradle 就像
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.2.0'
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: '5.2.0'
testRuntime group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.2.0'
testRuntime("org.junit.platform:junit-platform-launcher:1.1.1")
testCompile group: 'org.powermock', name: 'powermock-api-mockito2', version: '2.0.0-beta.5'
testCompile group: 'org.mockito', name: 'mockito-core', version: '2.21.0'
testCompile group: 'org.mockito', name: 'mockito-junit-jupiter', version: '2.21.0'`
Run Code Online (Sandbox Code Playgroud)
当我尝试我的测试用例时
@ExtendWith(MockitoExtension.class)
@PrepareForTest(MyUtil.class)
public class MyTest {
@Test
public void shouldCheckIfSyncTimeIsAboveThreshold() {
mockStatic(MyUtil.class);
when(MyUtil.getValue()).thenReturn(5));
}
Run Code Online (Sandbox Code Playgroud)
但是当我运行这个时,我得到了像
org.powermock.api.mockito.ClassNotPreparedException:
The class MyUtil not prepared for test
Run Code Online (Sandbox Code Playgroud)
有什么办法可以让我达到同样的目标
| 归档时间: |
|
| 查看次数: |
11411 次 |
| 最近记录: |