且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

VS 2013 MSTest与nUnit与xUnit

更新时间:2023-11-30 17:54:10

我因为在NUnit上工作而有偏见,但是NUnit或xUnit的优点是两个框架都提供了更多功能,例如数据驱动测试,并行执行和主机的高级功能.

I am biased because I work on NUnit, but the advantage of NUnit or xUnit is that both frameworks offer more functionality like data driven tests, parallel execution and a host of advanced features.

也就是说,MSTest没什么问题,特别是如果您的团队对单元测试没有很丰富的经验.它与Visual Studio和TFS很好地集成在一起,因此添加测试非常轻松. NUnit和xUnit都可以很好地集成,但是它们可能需要更多的设置.

That said, there is nothing wrong with MSTest especially if your team is not very experienced with unit testing. It is well integrated with Visual Studio and with TFS, so adding tests is fairly painless. Both NUnit and xUnit integrate well too, but they may require more setup.

继续,从MSTest开始.这是单元测试的简单介绍.如果您开始遇到MSTest的某些限制,那么向NUnit或xUnit迁移是相当容易的.对于简单的情况,只需更改NuGet软件包,然后查找/替换属性即可.

Go ahead and start with MSTest. It is an easy introduction to unit testing. If you start running into some of the limitations of MSTest, then it is a fairly easy migration to NUnit or xUnit. For simple cases, it is just a matter of changing your NuGet packages and then find/replace the attributes.

在xUnit和NUnit之间进行选择时,两者都是不错的选择,但每个都有不同的理念. NUnit趋向于更加灵活,并且允许多种测试样式,并且可以用于集成测试.但是,它足够灵活,可以让您用脚射击,也可以编写纯粹主义者不愿接受的测试. NUnit的选择权由您决定.

When it comes to choosing between xUnit and NUnit, both are great choices but each has a different philosophy. NUnit tends to be more flexible and allows for a range of testing styles and can be used for integration tests. It is however flexible enough to allow you to shoot yourself in the foot and allows you to write tests that purists would frown upon. NUnit leaves the choice up to you.

xUnit往往有些自以为是,并且将您推向单元测试的成功之坑".以我的经验,这对于新建项目非常有用,但如果不进行重构,可能会使测试某些架构较差的棕色项目变得困难.

xUnit however tends to be a bit more opinionated and pushes you towards the 'pit of success' with unit testing. In my experience, it is great for green field projects, but it can make testing some poorly architected brown-field projects difficult without refactoring.

最后,这些测试框架都不会出错.

In the end, you can't go wrong with any of these test frameworks.