Microsoft.visualstudio.testtools.unittesting Mac

使用VS 2012自带的Unit Testing工具进行单元测试是非常方便的。网上关于这方面的例子很多,这篇随笔只起个人学习笔记之用,所以脉络不会很清晰。

  1. Microsoft.visualstudio.testtools.unittesting Mac Pro
  2. C# Assert

2020-2-9  I have issues while building a UnitTest project using C# from VS 2017 I have the following Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll assemblies on machine C:dir /s Microsoft. MSTest V2 is now supported on.NET Core 1.0 RTM. API changes in.NET Core 1.0 leading up to RTM (see #7754), were blocking users of the MSTest V2 packages we had released for.NET Core 1.0 RC2. Not any more (see #10713).

1、简单Demo:

  1. Microsoft.VisualStudio.TestTools.UnitTesting namespace is missing from GAC with VS2008 Team Edition Installed Answered RSS 2 replies Last post Apr 13, 2008 09:16 AM by eryn.
  2. Feb 24, 2017 For projects that support PackageReference, copy this XML node into the project file to reference the package.

待测试类:

测试代码:

Mac

2、测试准备和测试清理工作

如果我想在所有TestMethod执行前进行一些准备工作怎么办?答案是使用ClassInitialize。

如果我想在所有TestMethod执行完成后进行一些清理工作怎么办?答案是使用ClassCleanup。

如果我想在每个TestMethod执行前进行一些准备工作怎么办?答案是使用TestInitialize。

如果我想在每个TestMethod执行完成后进行一些清理工作怎么办?答案是使用TestCleanup。

如下:

3、[ExpectedException]

Unit Testing中的attribute除了最基本的TestClass、TestMethod以外,还有一些非常用但是可能有用的attribute。

[ExpectedException(exceptionType: Type]可以用来表明某个测试方法预期抛出某个异常,并且只有真的抛出异常时才通过测试。比如下面:

Mac

4、断言API

Assert类的静态方法如下,其中常用的包括AreEqual、AreNotEqual、AreSame、IsNull、IsTrue、Inconclusive和Fail

针对集合类型的断言方法:

针对字符串类型的断言方法:

5、针对ASP.NET的单元测试

这里推荐网上的一个系列博客,

ASP.NET单元测试系列1(新手上路):http://blog.miniasp.com/post/2010/09/14/ASPNET-MVC-Unit-Testing-Part-01-Kick-off.aspx

ASP.NET单元测试系列2(可测试性):http://blog.miniasp.com/post/2010/09/15/ASPNET-MVC-Unit-Testing-Part-02-Testability.aspx

ASP.NET单元测试系列3(使用Mock):http://blog.miniasp.com/post/2010/09/16/ASPNET-MVC-Unit-Testing-Part-03-Using-Mock-moq.aspx

ASP.NET单元测试系列4(单元测试的目的与价值):http://blog.miniasp.com/post/2010/09/17/ASPNET-MVC-Unit-Testing-Part-04-The-Purpose-and-Value.aspx

ASP.NET单元测试系列5(了解Stub):http://blog.miniasp.com/post/2010/09/18/ASPNET-MVC-Unit-Testing-Part-05-Using-Stub-Object.aspx

ASP.NET单元测试系列6(测试路由规则):http://blog.miniasp.com/post/2010/09/23/ASPNET-MVC-Unit-Testing-Part-06-Routing.aspx

6、Visual Studio 2012 Fakes框架

7、其他资源(MSDN)

Real World Developer Testing with Visual Studio 2012: http://channel9.msdn.com/Events/TechEd/Europe/2012/AAP401

Microsoft.visualstudio.testtools.unittesting Mac Pro

Verifying Unit Testing by Using Unit Tests: http://msdn.microsoft.com/en-us/library/dd264975(v=vs.110).aspx

Mac

C# Assert

posted on 2012-11-21 16:31feichexia 阅读(...) 评论(...) 编辑收藏