开发者

Reasonable to remove TestContext from a unit test?

All my unit test classes have been created by Visual Studio 2008 from a built-in unit test template that includes a "Test开发者_JAVA技巧Context" property. So far I have not used a test context and this field is upsetting Resharper and code coverage.

Is it ok to remove TestContext or would doing that indicate my unit tests are poorly structured?


If you don't need it, remove it. You can always introduce it again afterwards. I've hardly used it too...


No harm in retaining the TestContext property, particularly if your unit test class makes use of data-driven test methods. Particularly useful if you use this type of statement:

Assert.AreEqual(myValue, this.TestContext.DataRow["ExpectedValue"].ToString())

Conversely, if you're using a hand-coded test class (i.e. not one generated by the VS "Add New Item" menu option), adding a property declaration as follows gives you instant access to the record of test data as it relates to the current unit test:

public TestContext TestContext { get; set; }

Hope that helps!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜