Reputation: 1
I have a public class a and I want to test its public method b. Its a void method. Q1 - What should I test in this void method? Q2 - How can I avoid testing the private methods that are being called in public methods?
I am using Moq framework.
public class a
{
public void b( x, y ,z)
{
c(y, z)
d(x)
}
private void c(i, j)
{
}
private void d(k)
{
}
}
All the methods are in same class.
Upvotes: 0
Views: 116
Reputation: 59238
What should I test in this void method?
A void method always has a side effect. If not, it would be useless. So you measure that side effect.
How can I avoid testing the private methods that are being called in public methods?
You don't avoid testing c
and d
implicitly. They are required for b
to do its job. Without c
and d
, b
would be empty and thus not fulfill the test criteria. What you should avoid is testing private methods explicitly.
If you wanted to avoid testing c
and d
, you could inline them both into b
- which makes size, complexity and readability of b
worse. You certainly don't want that.
Why don't you want to test private methods explicitly? Because you're testing an implementation detail and make the code rigid. If you expect method c
to exist in a test, a developer cannot remove it. But maybe it could be removed, e.g. because it's so simple that it can actually be inlined. Developers need some flexibility. Otherwise they change something and dozens of tests fail, which creates a lot of work.
Upvotes: 2