關于 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 Test 10 { 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
就記錄到這里。
文章列表