Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 您在单元测试中使用TestContext吗?_C#_Unit Testing_Mstest - Fatal编程技术网

C# 您在单元测试中使用TestContext吗?

C# 您在单元测试中使用TestContext吗?,c#,unit-testing,mstest,C#,Unit Testing,Mstest,我想知道,VisualStudio使用TestContext成员生成测试类,并将其实例传递给ClassInitialize方法。但是真的,你用这个类吗?如果是这样的话,哪些是方便/需要使用它的好例子 我编写测试已经有一段时间了,从来没有真正觉得需要使用TestContext。你呢?TestContext通常用于提供额外的上下文,如所需的路径信息、web服务、页面对象或某些数据访问方式 在我看来,如果一个测试需要这个,我们根本就不讨论单元测试。因此,如果您没有找到在单元测试中使用TestConte

我想知道,VisualStudio使用
TestContext
成员生成测试类,并将其实例传递给
ClassInitialize
方法。但是真的,你用这个类吗?如果是这样的话,哪些是方便/需要使用它的好例子


我编写测试已经有一段时间了,从来没有真正觉得需要使用
TestContext
。你呢?

TestContext
通常用于提供额外的上下文,如所需的路径信息、web服务、
页面
对象或某些数据访问方式

在我看来,如果一个测试需要这个,我们根本就不讨论单元测试。因此,如果您没有找到在单元测试中使用
TestContext
的理由,那么我认为您做得很好


当涉及到集成测试时,这会非常方便。

嗯,我用它来获取测试输入/输出目录的位置,并加载/保存测试所需或生成的文件。此外,还可以将消息打印到测试结果中


我认为完全不使用上下文就可以编写单元测试,但我从未在非平凡的测试场景中遇到过这种情况

我想指出,
TestContext
是测试期间访问数据的最简单(唯一?)的方法。我使用它非常成功。来自MSDN: