I recently received some feedback about some tests we wrote a long time ago from a contractor for a legacy application. I am confused with the terminology that he used and I won't get chance to talk to him again for another month (when I will speak to him). Please see the code below:
[TestMethod]
public void Is_Correct_Months()
{
IService service = new Service();
DataTable t1 = service.GetMonths();
DataTable t2 = BuildExpectedTable();
Assert.IsNotNull(t1);
Assert.AreEqual(t1.Rows.Count, t2.Rows.Count);
for (int i = 0; i <= 2; i++)
{
Assert.AreEqual(t1.Rows[i][0], t2.Rows[i][0]);
Assert.AreEqual(t1.Rows[i][1], t2.Rows[i][1]);
}
}
public DataTable BuildExpectedTable()
{
DataTable dt = new DataTable();
//Add column names to datatable
dt.Columns.Add("Column1", typeof(string));
dt.Rows.Add("January");
dt.Rows.Add("May");
dt.Rows.Add("December");
return dt;
}
Question: Is the BuildExpectedTable method a Stub or not in this case? Is it a bad idea to Assert against BuildExpectedTable (as I have done)?
Now see the code below:
var mockCalculator = new Moq.Mock<ICalculator>();
mockChangeCalculator.SetupProperty(client => client.Number1, 400).SetupProperty(client => client.Number2, 200);
This is obviously a mock. Question: Could it ever be construed as a Stub?
Now see the code below:
int[] values = new int[] { 1, 3, 5, 9 };
IEnumerable<int> processed = ProcessInput(values);
int[] expected = new int[] { 1, 9, 25, 81 };
CollectionAssert.AreEqual(expected, processed);
Question: Is expected a stub in this case?
Update
[TestMethod]
public void Is_Correct_Months()
{
IService service = new Service();
DataTable t1 = service.GetMonths();
DataTable dt2 = new DataTable();
//Add column names to datatable
dt.Columns.Add("Column1", typeof(string));
dt.Rows.Add("January");
dt.Rows.Add("May");
dt.Rows.Add("December");
Assert.IsNotNull(t1);
Assert.AreEqual(t1.Rows.Count, t2.Rows.Count);
for (int i = 0; i <= 2; i++)
{
Assert.AreEqual(t1.Rows[i][0], t2.Rows[i][0]);
Assert.AreEqual(t1.Rows[i][1], t2.Rows[i][1]);
}
}