C# 中的 JUnit 等价于什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/174498/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 16:40:19  来源:igfitidea点击:

What is the equivalent to JUnit in C#?

c#unit-testingjunit

提问by Epaga

I am coming from Java and am currently working on a C# project. What is the recommended way to go about a) unit testing existing C# code and b) accomplishing TDD for C# development?

我来自 Java,目前正在从事 C# 项目。a) 对现有 C# 代码进行单元测试和 b) 为 C# 开发完成 TDD 的推荐方法是什么?

Also is there an equivalent to EMMA / EclEmma (free yet powerful code coverage tool) for Visual Studio and C# code?

还有用于 Visual Studio 和 C# 代码的等效于 EMMA / EclEmma(免费但功能强大的代码覆盖工具)吗?

采纳答案by Jacek Szymański

1 Nunit
2 NCoveror
3 PartCover(I never used it)

1 Nunit
2 NCover
3 PartCover(我从未使用过)

回答by Adam Haile

NUnitwould be it.

NUnit就是这样。

回答by Chris Wenham

NUnitis patterned after JUnit, but if you're using Visual Studio 2008 then consider the built-in unit testing framework.

NUnit是在 JUnit 之后设计的,但如果您使用的是 Visual Studio 2008,那么请考虑内置单元测试框架。

回答by Keith

NUnit, but NCover is only part of the answer as it isn't free. I've asked elsewhereabout that.

NUnit,但 NCover 只是答案的一部分,因为它不是免费的。我在别处问过这个问题。

回答by Darcy Casselman

VS2008 Professional has the Team System unit testing functionality baked in.

VS2008 Professional 内置了 Team System 单元测试功能。

回答by Chad Moran

NUnit for sure.

NUnit 是肯定的。

回答by Jon Skeet

Unit test framework: NUnit

单元测试框架:NUnit

Unit test runner: Various, but personally I like the one in ReSharper. (ReSharper costs money, but is easily worth it for the various productivity improvements.)

单元测试运行程序:各种,但我个人喜欢ReSharper 中的一个。(ReSharper 需要花钱,但对于各种生产力改进来说很值得。)

Coverage: NCover(I think this used to be free, but it now costs money. Hmm.)

覆盖范围:NCover(我认为这曾经是免费的,但现在要花钱。嗯。)

回答by Omar Kooheji

I'd install:

我会安装:

  1. NUnit for your Unit testing framework http://www.nunit.org/index.php
  2. Test driven.net for runing your tests http://www.testdriven.net/
  3. Rhino Mocks as your mockign framework http://ayende.com/projects/rhino-mocks.aspx
  1. NUnit 用于您的单元测试框架http://www.nunit.org/index.php
  2. 用于运行测试的 Testdriven.net http://www.testdriven.net/
  3. Rhino Mocks 作为你的模拟框架http://ayende.com/projects/rhino-mocks.aspx

As and aside I find it odd that the NUnit guys seem to be using php to host their homepage...

顺便说一句,我觉得奇怪的是,NUnit 的家伙似乎正在使用 php 来托管他们的主页......

回答by Oliver Hallam

I would highly recommend Gallio(formally mbUnit) for unit testing, and (unfortunately not free) NCover for code coverage.

我强烈推荐Gallio(正式名称为 mbUnit)进行单元测试,以及(不幸的是不是免费的)NCover 进行代码覆盖。

回答by aridlehoover

Regarding your question about unit test frameworks:

关于您关于单元测试框架的问题:

NUnit1.0 was a direct port of JUnit. NUnit 2.0 moved away from JUnit syntax in order to take advantage of the .NET platform. xUnit.netis a newer unit test framework (from Jim Newkirk - one of the NUnit 2.0 developers - and Brad Wilson) that states as a goal exposing "advances in other unit test library implementations that have not really surfaced in .NET," which I read as "keeping up with JUnit."

NUnit1.0 是 JUnit 的直接移植。NUnit 2.0 放弃了 JUnit 语法以利用 .NET 平台。xUnit.net是一个较新的单元测试框架(来自 Jim Newkirk - NUnit 2.0 开发人员之一 - 和 Brad Wilson),它的目标是公开“其他单元测试库实现的进步,但在 .NET 中并没有真正浮出水面”,我读为“跟上 JUnit 的步伐”。