xUnit for vs2012/vs2013

来源:互联网 发布:win10更改网络类型 编辑:程序博客网 时间:2024/04/26 01:18

关于 NUint 以及单元测试的相关内容,可以参考:【单元测试】NUint使用详解及Visual Studio配置。

  xUnit 是 NUint 的进化版本,使用方法和 NUint 类似,首先下载安装一个“xUnit.net runner for Visual Studio 2012 and 2013”,下载地址:http://visualstudiogallery.msdn.microsoft.com/463c5987-f82b-46c8-a97e-b1cde42b9099,然后使用 NuGet 命令添加引用包:install-package xunit

  测试示例代码:

复制代码
 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using Xunit; 6  7 namespace DemoTests 8 { 9     public class Test10     {11         [Fact]12         public void TestMethod()13         {14             Assert.Equal("1", "1");15         }16     }17 }
复制代码

  xUnit 的使用很简单,不像 NUint 需要在测试类前加 TestFixture 标记,而只需要在测试方法前加 Fact 标记就可以了,其他的使用方法(比如断言)和 NUint比较类似。

  关于 xUnit 在 vs2012/vs2013 中的使用,只需要安装“NUnit Test Adapter”即可,使用方法和 NUint 类似,“NUnit Test Adapter”目前支持以下测试框架:

  • NUnit
  • xUnit.net
  • MbUnit
  • QUnit
  • Jasmine 

  “NUnit Test Adapter”的安装使用,可以参照:http://www.cnblogs.com/xishuai/p/3728576.html#xishuai_h4_3

  在生成解决方案后,会自动检测解决方案中所包含的测试用例:

  vs2013 需要安装:https://xunit.codeplex.com/releases

  就记录到这里。

0 0
原创粉丝点击