C# NUnit 示例代码?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/860594/
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-05 04:35:28  来源:igfitidea点击:

NUnit example code?

c#unit-testingnunit

提问by Rodney Schuler

I would like to learn how to use NUnit. I learn best by reading then playing with real code. Where can I find a small, simple C# project that uses NUnit in an exemplary manner?

我想学习如何使用 NUnit。我通过阅读然后玩真正的代码来学习最好。在哪里可以找到以示例方式使用 NUnit 的小型简单 C# 项目?

采纳答案by Yes - that Jake.

There are many fine examples on NUnit's developer wiki.

NUnit's developer wiki上有很多很好的例子。

Update as the original link is broken:

由于原始链接已损坏而更新

Basic examples can be found on the NUnit Documentation Page. Check out the Getting Started/QuickStart subsection, and the Assertions/* subsection.

可以在NUnit 文档页面上找到基本示例。查看 Getting Started/QuickStart 小节和 Assertions/* 小节。

回答by Paul Sonier

You should find NUnit samples in with the download of NUnit; these are very good examples of how to use NUnit.

您应该可以通过下载 NUnit 找到 NUnit 示例;这些是如何使用 NUnit 的很好的例子。

回答by Jon Skeet

From my own projects (real life, so not just demos where everything will be nice and simple :)

来自我自己的项目(现实生活,所以不仅仅是演示,一切都会变得美好而简单:)

Both are reasonably small, and although MiscUtil is the bigger of the two, it's mostly a collection of very small, individual components.

两者都相当小,虽然 MiscUtil 是两者中较大的一个,但它主要是非常小的单个组件的集合。

MoreLINQ is heavily tested; MiscUtil has patchier coverage as I started it before getting into unit testing.

MoreLINQ 经过严格测试;在进入单元测试之前,我开始使用 MiscUtil 时覆盖范围更广。

回答by Ali Shafai

I don't think reading unit tests helps as much as seeing someone writing them and explaining why they are doing the way they are. try some screencasts. DimeCast.Net for example....

我不认为阅读单元测试比看到有人编写它们并解释他们为什么这样做更有帮助。尝试一些截屏视频。例如 DimeCast.Net....

回答by Vadim

I would recommend to watch video on TDD at dnrTV. See Part 1and Part 2.

我建议在 dnrTV 上观看有关 TDD 的视频。参见第 1部分第 2 部分

回答by Yasser Shaikh

This should be useful...

这个应该有用...

using System.Text;
using NUnit.Framework;

namespace Test.SampleTests
{
    [TestFixture]
    public class CustomerTestClass
    {
        [TestCase(1, true)] // valid customer
        [TestCase(2, true)] // valid customer
        [TestCase(1123123123132, false)] // invlaid customer
        public void IsValidCustomerTest(int customerId, bool isValid)
        {
            Assert.AreEqual(_service.ValidateCust(customerId), isValid);
        }
    }
}

Taken from here - https://coderwall.com/p/vwvura

取自这里 - https://coderwall.com/p/vwvura