Reputation:
In a unit test, how can I ignore a call to a method as shown below?
void methodToBeTested(){
// do some stuff
methodToBeSkipped(parameter);
// do more stuff
}
void methodToBeSkipped{
// do stuff outside of test scope
}
@Test
void TestMethodToBeTested(){
TestedClass testedClass = new TestedClass();
testedClass.methodToBeTested();
// asserts etc.
}
Upvotes: 1
Views: 2883
Reputation: 310993
You don't need powermockito for this. You could simply spy
the object you're going to test and mock out the method you want to skip:
@Test
public void testMethodToBeTested() {
TestedClass testedClass = Mockito.spy(new TestedClass());
Mockito.doNothing().when(testedClass).methodToBeSkipped();
testedClass.methodToBeTested();
// Assertions etc.
}
Upvotes: 6