如何将现有程序集转换为 MS 单元测试程序集?
在 Visual Studio 2010 Pro 中,如何轻松地将经典程序集转换为 ms 单元测试程序集?
.csproj 文件中有一个要激活的标志吗?
In Visual Studio 2010 Pro, how can I easily convert a classic assembly to a ms unit test assembly ?
It there a flag to activate in the .csproj file ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
问题是测试项目被“标记”在项目文件上 - 您可以按照以下四个简单步骤将类库转换为测试项目:
将以下行添加到项目中
C#:
<前><代码><项目>;
{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
<财产组>
<程序集名称>....
VB - <代码>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{F184B08F-C81C-45F6-A57F-
5ABD9991F28F}
将以
请注意,您需要手动添加对 Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll 的引用,以便能够使用测试相关属性
更新:在即将推出的 MSTest V2 中,这将不再是必要的,因为 MSTest 成为一个 NuGet 包,其工作方式与 NUnit/XUnit 类似
The problem is that test projects are "marked" on the project file - you can convert a class library to Test project follow these four simple steps:
add the following line to the project
C#:
VB -
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{F184B08F-C81C-45F6-A57F-
5ABD9991F28F}</ProjectTypeGuids>
Note that you'll need to manually add reference to Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll in order to be able to use test related attributes
Update: In the upcoming MSTest V2 this will not be nesessery as MSTest becomes a NuGet package which works just like NUnit/XUnit
在 Visual Studio 2017 中,您可以将 nuget 包
MSTest.TestAdapter
和MSTest.TestFramework
添加到您的 C# 项目,然后使用[TestClass]
与[TestMethod]
属性。它们将被自动发现并列在测试资源管理器
中。无需手动添加ProjectTypeGuids
即可启用测试。In Visual Studio 2017 you can add nuget packages
MSTest.TestAdapter
andMSTest.TestFramework
to your C# project and from then on use[TestClass]
with[TestMethod]
attributes. They will be automatically discovered and listed in theTest Explorer
. A manual addedProjectTypeGuids
is not needed to enable tests.单元测试项目只是类库,其中包含具有属性 [TestClass] 的类,并且 .csproj 文件没有任何标志。您可以将类添加到您的项目中并设置属性[TestClass],它将成为测试类。
Unit Test Project is only Class Library which have classes with attribute [TestClass], and .csproj file doesn't have any flags. You can add class to your project and set attribute [TestClass] and it will be test class.