3 回答
TA贡献1802条经验 获得超4个赞
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | package cn.outofmemory.junit.jmockit;
import mockit.NonStrictExpectations; import mockit.Injectable; import mockit.MockUp; import mockit.Mocked; import mockit.Mockit; import mockit.NonStrict; import mockit.Tested;
public class MockTargetTest {
@BeforeClass static public void beforeClass() { Mockit.setUpMocks(); } @Mocked private MockTarget mt;
@Test public void testPrivateMethodMock() { new NonStrictExpectations(mt) { { // 对私有方法进行mock this.invoke(mt, "privateMethod", anyString); result = "Hello Object"; } };
Object actual = mt.publicMethod(); assertEquals(actual,"Hello Object"); } } |
- 3 回答
- 0 关注
- 924 浏览
添加回答
举报