【发布时间】:2016-06-16 16:17:12
【问题描述】:
我在我的项目中使用 PowerMock 和 EasyMock。调用 Easymock.expect() 方法调用时出现空指针异常。
JUnit 类:
import static org.easymock.EasyMock.*;
@RunWith(PowerMockRunner.class)
@PrepareForTest({InfoDao.class})
public class AdminUtilTest {
//mocking interface
@Mock
InfoDao infoDaoMock;
@Test
public void testSetUp() {
assertNotNull(infoDaoMock);
}
@Test
public void initInfoTest() throws Exception {
// getting null pointer exception in this line..
expect(infoDaoMock.getGroupInfoById(isA(Long.class))).andReturn("testString");
replay(infoDaoMock);
/*rest of the code*/
}
}
testSetUp 不为空,assertNotNull 成功。
我也试过了:
InfoDao infoDaoMock = createMock(InfoDaoMockImpl.class);
这也是在抛出NullPointerException。我在这里做错了什么?
【问题讨论】:
-
你能发布堆栈跟踪吗?
标签: java unit-testing junit4 powermock easymock