Consider the following class:
public class MyIntSet
{
private List<int> _list = new List<int>();
public void Add(int num)
{
if (!_list.Contains(num))
_list.Add(num);
}
public bool Contains(int num)
{
return _list.Contains(num);
}
}
Following the principle of "only one test", suppose I want to test the "Add" function. Consider the following possibility for such a test:
[TestClass]
public class MyIntSetTests
{
[TestMethod]
public void Add_AddOneNumber_SetContainsAddedNumber()
{
MyIntSet set = new MyIntSet();
int num = 0;
set.Add(num);
Assert.IsTrue(set.Contains(num));
}
}
My problem with this solution is that it actually tests 2 methods : Add () and Contains (). Theoretically, in both cases there may be an error that appears only in scenarios where they are not called one after another. Of course, Contains () is now a server like a thin shell for List Contains (), which should not be tested on its own, but what if in the future it changes to something more complex? Perhaps a simple βthin packβ method should always be kept for testing purposes?
(, InternalsVisibleTo PrivateObject) _list- , , - - (, C5).
?
- ?
,
JC