I hope that we can finally do row tests ([RowTest] attribute) in Visual Studio 2010, like we can in mbUnit and nUnit.
That would make our data driven unit tests so much easier!!!
But nothing to find on the official VS2010 webpage or Soma’s Blog Search for Rowtest
[TestMethod]
[DeploymentItem(@"TestData\validConditions.txt")]
[DeploymentItem(@"TestData\schema.ini")]
[DataSource("System.Data.OleDb", @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|;Extended Properties='text;FMT=TabDelimited;HDR=YES'", @"validConditions#txt", DataAccessMethod.Sequential)]
public void ValidateRulesEntry_Valid_ValidConditionsFromFile()
{
string condition = TestContext.DataRow[0].ToString();
string returnMessage;
bool successFul = CodeParserTryParseCondition(condition, "No error", out returnMessage);
Assert.IsTrue(successFul, string.Format("Condition: {0}. Error: {1}.", condition, returnMessage));
}
BAD: Input data is in a text file, to view that data I have to open the text file
[TestMethod]
[RowTest]
[Row("Target.IsDirty")]
[Row("Target.IsValid")]
[Row("Target.Description.Contains(""Test"")")]
[Row("(1 != 2)")]
public void ValidateRulesEntry_Valid_ValidConditionsFromFile()
{
string condition = TestContext.DataRow[0].ToString();
string returnMessage;
bool successFul = CodeParserTryParseCondition(condition, "No error", out returnMessage);
Assert.IsTrue(successFul, string.Format("Condition: {0}. Error: {1}.", condition, returnMessage));
}
GOOD: Input data for unit test is attached to unit test itself --> easy to read, understand!
No comments:
Post a Comment