Say we have this hyper simple class hierchy:
public class SomeMath
{
public int Add(int x, int y)
{
return x + y;
}
}
public class MoreMath : SomeMath
{
public int Subtract(int x, int y)
{
return x - y;
}
}
Should I write tests for the Add
method when I write tests for the MoreMath
class? Or should I only care about that method when I am testing the SomeMath
class? More generally: Should I test all methods of a class, or should I only test "new" methods?
I can kind of come up with some reasons for both sides. For example, when testing all methods you will end up testing the same thing more than once, which is not so good and can become tedious. But if you don't test all methods, a change in SomeMath
might break usages of MoreMath
? Which would kind of be a bad thing too. I suppose it probably depends a bit on the case too. Like if it extends a class I have control over or not. But anyways, I'm a total test newbie, so I am curious to know what people smarter than I think about this :-)