简体   繁体   English

c#中的单元测试项目和带有xunit的类库之间的区别

[英]Difference between Unit tests project in c# and a class library with xunit

Ok so I have been a long time xunit user, and I have always used it in a class library. 好的,我已经很久了xunit用户,我一直在类库中使用它。 Infact I didn't even realize there was an actual unit tests project type. 事实上,我甚至没有意识到有一个实际的单元测试项目类型。

So my question is...what do you get in a unit tests project you do not get in regular project types? 所以我的问题是......你在常规项目类型中没有得到的单元测试项目是什么?

The benefit of the Unit Test project is that the IDE (Visual Studio) recognizes the project, and searches it for tests (like what @Emmanuel Istace indicates). 单元测试项目的好处是IDE(Visual Studio)识别项目,并搜索它以进行测试(如@Emmanuel Istace所指示的那样)。 The reason you might want to choose different unit test frameworks depends on what you're trying to test. 您可能希望选择不同的单元测试框架的原因取决于您要测试的内容。 For example, working on testing a multi-threading application using the C# ThreadPool in MSTest consistently hangs for me, so I use NUnit for those types of tests. 例如,使用MSTest中的C#ThreadPool测试多线程应用程序一直是我的问题,所以我使用NUnit进行这些类型的测试。

Bottom line is this: you should choose your test framework based on what you're trying to test, and choose the best fit. 底线是这样的:你应该根据你想要测试的东西选择你的测试框架,并选择最合适的。 Visual Studio does a decent job of supporting other test frameworks in VS2015 and VS2013/2012 (not sure about earlier versions), and really, whichever framework you choose, you'll likely end up using a Unit Test Project for it anyway. Visual Studio在支持VS2015和VS2013 / 2012中的其他测试框架方面做得不错(不确定早期版本),实际上,无论选择哪种框架,您最终都可能会使用单元测试项目。

A unit test project is a class library project, take a look at the csproj you'll see there's nothing fundamentally different. 单元测试项目是一个类库项目,看看csproj,你会发现没有什么根本不同的。

Unit test project include reference to MSTest and test runner. 单元测试项目包括对MSTest和测试运行器的参考。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM