我想在最终的utitlity类中测试一个私有方法.
1.班级本身:
班级签名是:
public final class SomeHelper {
/** Preventing class from being instantiated */
private SomeHelper() {
}
并且有私有方法本身:
private static String formatValue(BigDecimal value)
测试已经完成了,但是之前,该方法是在没有私有构造函数的非实用非final类中.
测试已经使用@RunWith(Parameterized.class).
现在我得到的只是一个例外:
org.mockito.exceptions.base.MockitoException:
Cannot mock/spy class com.some.package.util.SomeHelper
Mockito cannot mock/spy following:
- final classes
- anonymous classes
- primitive types
2.测试
该测试中最重要的一行是:
String result = Whitebox.invokeMethod(mValue, "formatValue", mGiven);
有没有办法让测试工作?