powermock @PrepareForTest不使用通配符值

She*_*jie 2 junit annotations powermock

版本: powermock-core 1.4.12

问题: 根据API文档,@ PrepareForTest应该能够采用以下通配符:

@PrepareForTest( "com.smin.*")

但在我的情况下,它只是简单地不编译,编译错误:

Type mismatch: cannot convert from String to Class<?>[]

我看了一下PrepareForTest的源代码,我只是看不出这个注释如何将通配符作为其值.有任何想法吗?

@Target( { ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
public @interface PrepareForTest {
    Class<?>[] value() default IndicateReloadClass.class;

    String[] fullyQualifiedNames() default "";
}
Run Code Online (Sandbox Code Playgroud)

Bri*_*nry 5

是的 - 文档似乎与现实并不相符.尝试:

@PrepareForTest(fullyQualifiedNames={"com.smin.*"})
Run Code Online (Sandbox Code Playgroud)

认为通配名称的解析会发生在MockClassLoader或者它的超类中DeferSupportingClassLoader,如果你想深入挖掘.