I met one problem to get coverage info when I use PowerMockito.
When I add my class(StorageServerImmMgr) in the @PrepareForTest list, then the
class StorageServerImmMgr test coverae result will always show 0%, when I
remove the class name from the list, the test coverage result is correct. But
after that, I can't use PowerMockito to mock System.exit(1) and my test will
stop by System.exit(1).
My class and test codes are as below, anycomments? Thanks!
@RunWith(PowerMockRunner.class)
@PrepareForTest({System.class,StorageServerImmMgr.class})
public class StorageServerImmMgrTest {
@Before
public void setUp() throws Exception {
...
}
@Test
public void testBind() throws Exception {
StorageServer ssBeanNull = null;
when(ssConfigContext.lookupTopLevelBean()).thenReturn(ssBeanNull);
PowerMockito.mockStatic(System.class);
immMgr = new StorageServerImmMgr();
PowerMockito.verifyStatic(times(1));
System.exit(1);
System.out.println("If this message displays them System.exit() was
mocked successfully");
}
public class StorageServerImmMgr{
private synchronized void bind() {
StorageServer storageServer =ssConfigContext.lookupTopLevelBean();
if (storageServer == null) {
System.exit(1);
}
}
}
--
You received this message because you are subscribed to the Google Groups
"JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.