MSTest.TestAdapter 与 MSTest.TestFramework 之间有什么区别,我什么时候需要哪一个?
What is the difference between MSTest.TestAdapter vs MSTest.TestFramework and when do I need which one?
MSTest.TestAdapter
与 MSTest.TestFramework
之间的实际区别是什么?我什么时候需要哪个?
在 NuGet 描述中,您可以阅读:
MSTest.TestAdapter
The adapter to discover and execute MSTest Framework based tests.
MSTest.TestFramework
This is MSTest V2, the evolution of Microsoft's Test Framework. + To discover and execute tests install MSTest.TestAdapter.
嗯,不是很有帮助,我总是安装这两个,因为我永远不确定我应该选择哪个。奇怪的是,在我的一个测试项目中,我只有 MSTest.TestFramework
(我猜是偶然的)并且 ReSharper 仍然可以发现测试。
我对这些软件包的问题是:
- 你真的总是需要安装它们吗?
- 为什么即使没有
TestAdapter
也能正常工作?
- 我可以用
TestFramework
做什么?我什么时候需要这个?
GitHub 上的项目页面也没有多大帮助。唯一的link
You can read more about MSTest V2 here.
导航到一个页面,该页面只说明它有多棒和开源,但没有具体说明这两个包。
Do you really always need to install both of them?
没有。为什么? (见下文)
Why does it work even without the TestAdapter?
还有其他 adapters/runners 可以识别 MSTest 框架,也可以发现和 运行 MSTest 框架测试。
What can I do with the TestFramework?
因此,一般来说,测试框架用于 create/author 您的测试,同时 adapters/runners 发现并执行发现的测试。
When would I need this one?
有多种框架,adapters/runners您可以使用自己选择的一种。
所以Visual Studio使用一个名为Visual Studio测试平台的框架来加载测试适配器,
https://github.com/Microsoft/vstest
为了发现或执行测试用例,VSTest 会根据您的项目配置调用测试适配器。 (这就是为什么 NUnit/xUnit/MSTest 都要求您将测试适配器 NuGet 包安装到您的单元测试项目中)。所以 MSTest.TestAdapter 就是为了这个目的而存在的。
MSTest.TestFramework 本身实现了测试框架及其契约。因此,您需要添加它的 NuGet 引用才能编写单元测试用例并进行编译。 Visual Studio.
只能使用已编译的项目和测试适配器
所以您问题的最终答案是 "you usually need both"。
如果您不打算使用 Visual Studio,@Nkosi 的另一个答案当然是正确的。 MSTest 有自己的命令行 运行ner,它可以 运行 您的单元测试项目而无需测试适配器。
MsTest.TestFramework 包含核心框架,其中包括属性和断言。 MsTest.TestAdapter 允许我们发现基于 MsTest 的测试并执行它们。例如,识别属性为 [TestMethod] 的方法并执行它们。
MSTest.TestAdapter
与 MSTest.TestFramework
之间的实际区别是什么?我什么时候需要哪个?
在 NuGet 描述中,您可以阅读:
MSTest.TestAdapter
The adapter to discover and execute MSTest Framework based tests.
MSTest.TestFramework
This is MSTest V2, the evolution of Microsoft's Test Framework. + To discover and execute tests install MSTest.TestAdapter.
嗯,不是很有帮助,我总是安装这两个,因为我永远不确定我应该选择哪个。奇怪的是,在我的一个测试项目中,我只有 MSTest.TestFramework
(我猜是偶然的)并且 ReSharper 仍然可以发现测试。
我对这些软件包的问题是:
- 你真的总是需要安装它们吗?
- 为什么即使没有
TestAdapter
也能正常工作? - 我可以用
TestFramework
做什么?我什么时候需要这个?
GitHub 上的项目页面也没有多大帮助。唯一的link
You can read more about MSTest V2 here.
导航到一个页面,该页面只说明它有多棒和开源,但没有具体说明这两个包。
Do you really always need to install both of them?
没有。为什么? (见下文)
Why does it work even without the TestAdapter?
还有其他 adapters/runners 可以识别 MSTest 框架,也可以发现和 运行 MSTest 框架测试。
What can I do with the TestFramework?
因此,一般来说,测试框架用于 create/author 您的测试,同时 adapters/runners 发现并执行发现的测试。
When would I need this one?
有多种框架,adapters/runners您可以使用自己选择的一种。
所以Visual Studio使用一个名为Visual Studio测试平台的框架来加载测试适配器,
https://github.com/Microsoft/vstest
为了发现或执行测试用例,VSTest 会根据您的项目配置调用测试适配器。 (这就是为什么 NUnit/xUnit/MSTest 都要求您将测试适配器 NuGet 包安装到您的单元测试项目中)。所以 MSTest.TestAdapter 就是为了这个目的而存在的。
MSTest.TestFramework 本身实现了测试框架及其契约。因此,您需要添加它的 NuGet 引用才能编写单元测试用例并进行编译。 Visual Studio.
只能使用已编译的项目和测试适配器所以您问题的最终答案是 "you usually need both"。
如果您不打算使用 Visual Studio,@Nkosi 的另一个答案当然是正确的。 MSTest 有自己的命令行 运行ner,它可以 运行 您的单元测试项目而无需测试适配器。
MsTest.TestFramework 包含核心框架,其中包括属性和断言。 MsTest.TestAdapter 允许我们发现基于 MsTest 的测试并执行它们。例如,识别属性为 [TestMethod] 的方法并执行它们。