在对一个private方法测试的时候,发现Mockito出现了无法测试的情况,所以选择了PowerMock,但是按照网上的步骤一步步的走下来发现会卡住,在使用@Runwith注释时无法引入PowerMockRunner.class。
后来谷歌了一下,发现是少引入了一个模块,添加上之后再
import org.powermock.modules.junit4.PowerMockRunner;
随后再在类头加入
@RunWith(PowerMockRunner.class)
于是不报错了,再在这里附上引入的jar包
testImplementation 'junit:junit:4.11'
// required if you want to use Mockito for unit tests
testImplementation 'org.mockito:mockito-core:1.9.5'
// required if you want to use Powermock for unit tests
testImplementation 'org.powermock:powermock-module-junit4:1.5.6'
testImplementation 'org.powermock:powermock-module-junit4-rule:1.5.6'
testImplementation 'org.powermock:powermock-api-mockito:1.5.6'
implementation 'org.powermock:powermock-module-junit4:2.0.0'
implementation 'org.mockito:mockito-android:2.23.4'