Reputation: 39
public void publicMethod() {
for (i=1;i<10;i++)
privateMethod();
}
private privateMethod() {
something...
}
I need to write a JUnit testcase to verify the number of times the privateMethod()
is called.
Upvotes: 3
Views: 3155
Reputation: 140523
You shouldn't do that. You don't write unit tests to verify implementation details.
Your tests make sure that your public methods fulfill their contract. So you assert that things returned are as expected; or that subsequent calls to other methods give the desired output. Or you expect calls to throw specified exceptions. Or, third option: you injected mocked objects; which you later on verify that the mocks saw the method calls you specified upfront.
But writing test cases to specifically test private methods is really bad practice!
Upvotes: 11