开发者

Reasonable to remove TestContext from a unit test?

开发者 https://www.devze.com 2023-01-25 20:55 出处:网络
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 t

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

精彩评论

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