I have a test method that tests the ToString() method of a class against known good outputs.
/// <summary>
///A test for ToString
///</summary>
[TestMethod()]
public void ToStringTest()
{
string input = System.IO.File.ReadAllText(@"c:\temp\input2005.txt");
MyClass target = new MyClass(input);
string expected = System.IO.File.ReadAllText(@"c:\temp\output2005.txt");
string actual;
actual = target.ToString();
Assert.AreEqual(expected, actual);
}
The method works great, but I already have several pairs of input/output files. Experience tells me that I don’t want to write a separate test method for each pair. I also don’t want to loop through each pair of files because I won’t know which pair caused the test to fail. What do I do?
If you wish to test all pairs of files, you could put the file that failed as a message to the assertion:
This would print out a message telling you which file the failure occured on.
Additionally, you could specify your strings inside of the test itself instead of putting them in extrenal files. I’m not sure how your tests are setup but if you did that you wouldn’t have to worry about the external depencies of the file paths:
This would keep all of your test data together.