Junit 表表达式

Junit 表表达式,junit,ejb,mockito,schedule,Junit,Ejb,Mockito,Schedule,我正在尝试为包含ScheduleExpression的方法创建Junit测试。我已经尝试使用PowerMockito来模拟它,但是我仍然收到一条错误消息 java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/ejb/ScheduleExpression 下面是我如何使用PowerMockito的 ScheduleExpres

我正在尝试为包含ScheduleExpression的方法创建Junit测试。我已经尝试使用PowerMockito来模拟它,但是我仍然收到一条错误消息

java.lang.ClassFormatError: Absent Code attribute in method 
that is not native or abstract in class file javax/ejb/ScheduleExpression
下面是我如何使用PowerMockito的

 ScheduleExpression expression = PowerMockito.mock(ScheduleExpression.class);
我试过注释

@RunWith(PowerMockRunner.class)
@PrepareForTest(Static.class)
但它们没有起作用

我也尝试过Mockito版本1.9.5,但我得到了相同的错误。我是否缺少pom依赖项


有没有办法模拟ScheduleExpression?

您必须使用希望PowerMock准备的类的名称

@PrepareForTest(ScheduleExpression.class)

但是,在您的情况下,我认为没有必要使用PowerMock,因为
ScheduleExpression
不是final,或者您可能试图模拟私有或静态方法

试着用香草味的Mockito而不是像这样的PowerMockito

@RunWith(MockitoJUnitRunner.class)
...
ScheduleExpression expression = Mockito.mock(ScheduleExpression.class);

谢谢你的回答,但遗憾的是,这并没有解决我的问题。我认为这可能是由于缺少了Maven依赖性造成的。如果您按照我的建议只使用
MockitoJUnitRunner
的话,您需要的唯一依赖性就是和。我自己测试了mocking
ScheduleExpression
。不确定一定是环境问题,因为它正在另一个项目中工作。谢谢你的帮助