我刚刚升级到Mockito v 1.10.18(使用JUnit 4.12和PowerMock 1.6.2)。过去常常工作......
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({ "classpath:test-context.xml" })
@DirtiesContext(classMode = ClassMode.AFTER_CLASS)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@PrepareForTest( Transport.class )
public class AccessCodeServiceIT
{
@Rule
public PowerMockRule rule = new PowerMockRule();
…
@Autowired
private EmailService m_emailSvc;
@Before
public final void setup()
{
final EmailService emailSvcSpy = (EmailService) Mockito.spy(getTargetObject(m_emailSvc));
但现在使用Mockito的新版本,我在上面的行中得到以下异常......
findAccessCodeByCode(org.mainco.subco.ecom.service.AccessCodeServiceIT) Time elapsed: 1.588 sec <<< ERROR!
java.lang.ClassCastException: org.mainco.subco.email.service.EmailServiceImpl cannot be cast to java.lang.Class
at org.mainco.subco.ecom.service.AccessCodeServiceIT.setup(AccessCodeServiceIT.java:103)