我的问题是我正在尝试模拟BluetoothDevice进行一些测试,但这是最后一课。因此,要使用PowerMock进行模拟,我必须使用@PrepareForTest
注释。但是,当我说@PrepareForTest({BluetoothDevice.class})
时,我得到一个例外。这是错误输出的前几行:
java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
at sun.reflect.annotation.AnnotationParser.parseClassArray(Unknown Source)
at sun.reflect.annotation.AnnotationParser.parseArray(Unknown Source)
at sun.reflect.annotation.AnnotationParser.parseMemberValue(Unknown Source)
这是我正在使用的代码(测试仍然需要填写,我只是在减少变量):
@RunWith(PowerMockRunner.class)
@PrepareForTest({ BluetoothDevice.class })
public class BluetoothCommTest {
@Test
public void testBluetoothComm() {
fail("Not yet implemented");
}
}
感谢您的帮助!
答案 0 :(得分:1)
我弄清楚发生了什么事。我按照this page上的说明操作,他们提供的android.jar已经过时了,并没有包含蓝牙库。
为了解决这个问题,我使用了Powermock 1.2.5和Android 15 SDK附带的android.jar。