我试图嘲笑与JMockit一个DAO:嘲笑接口为空
public interface MyDao {
Details getDetailsById(int id);
}
利用这种测试类:
public class TestClass {
@Test
public void testStuff(final MyDao dao) throws Exception
{
new Expectations()
{
{
// when we try to get the message details, return our sample
// details
dao.getDetailsById((Integer) any); ***THROWS AN NPE
result = sampleDetails;
}
};
ClassUsingDao daoUser = new ClassUsingDao(dao);
// calls dao.getDetailsById()
daoUser.doStuff();
}
当DAO对象是在预期块使用的,NPE是抛出。我试着将dao的声明移动到用@Mocked注释的成员变量,但同样的事情发生。我也尝试过使用MyDao的具体实现,并且发生同样的事情。
你用春天吗? – iddqd
不,这个类目前没有使用Spring,但将来可能会用于将Dao注入到ClassUsingDao中。 – Brian