更新时间:2021-12-30 03:01:34
由于MessageDigest
是Java系统类,因此您需要按照以下方式分别处理它们: https://github.com/powermock/powermock/wiki/Mock-System
As MessageDigest
is a Java system class, you need to deal with them differently as per: https://github.com/powermock/powermock/wiki/Mock-System
因此,在@PrepareForTest
批注中声明测试类,如下所示:
@PrepareForTest({MessageDigest.class, MyTest.class})
So declare the test class in the @PrepareForTest
annotation as follows:
@PrepareForTest({MessageDigest.class, MyTest.class})
不确定此注释是否按照您的示例作为方法级别使用,但应在类级别使用:
Not sure if this annotation works as method level as per your example, but it should at class level:
@RunWith(PowerMockRunner.class)
@PrepareForTest({MessageDigest.class, MyTest.class})
public class MyTest {