Enlightment?
Or maybe it is just me being stupid.
I had trouble recently with testing methods that return object
graphs, the test would look like:
Assert.AreEqual(1, graph.Items[0].Count);
Assert.AreEqual(0, graph.Items[1].Count);
Assert.AreEqual(1, graph.Items[2].Count);
I just couldn’t stand the code, but I couldn’t
think of a way to make it better, so I mostly tried to use Fit to do them,
since it’s far more natural to do it this way.
Today I had to write another one of those tests, but this
time I needed to do it in C#, and it just clicked, I can do this:
int [] expected = new int [] { 1,0,1};
for(int i=0;i<3;i++)
Assert.AreEqual(expected[i[, graph.Items[i].Count, “Error on {0}”,
i+1);
Now I’m feeling stupid that I didn’t figure it
out in the first place.
Comments
Comment preview