1
A
回答
2
你可能已經完成了一個不同的途徑,但我會盡我所能分享這一點。在後2.5版的NUnit中,實現了通過外部源驅動測試用例的能力。我做了一個使用CSV文件的簡單示例演示。
CSV是包含我的兩個測試輸入和預期結果的東西。所以1,1,2爲第一等等。
CODE
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
namespace NunitDemo
{
public class AddTwoNumbers
{
private int _first;
private int _second;
public int AddTheNumbers(int first, int second)
{
_first = first;
_second = second;
return first + second;
}
}
[TestFixture]
public class AddTwoNumbersTest
{
[Test, TestCaseSource("GetMyTestData")]
public void AddTheNumbers_TestShell(int first, int second, int expectedOutput)
{
AddTwoNumbers addTwo = new AddTwoNumbers();
int actualValue = addTwo.AddTheNumbers(first, second);
Assert.AreEqual(expectedOutput, actualValue,
string.Format("AddTheNumbers_TestShell failed first: {0}, second {1}", first,second));
}
private IEnumerable<int[]> GetMyTestData()
{
using (var csv = new StreamReader("test-data.csv"))
{
string line;
while ((line = csv.ReadLine()) != null)
{
string[] values = line.Split(',');
int first = int.Parse(values[0]);
int second = int.Parse(values[1]);
int expectedOutput = int.Parse(values[2]);
yield return new[] { first, second, expectedOutput };
}
}
}
}
}
然後,當你與NUnit的UI看起來運行它(我包括例如目的失敗:
+0
好的例子謝謝。我可以建議更改TestCaseSource(「GetMyTestData」)以使用nameof - TestCaseSource(nameof(GetMyTestData)),該方法也需要是靜態的 – wnbates 2016-12-14 12:19:42
相關問題
- 1. 如何將動態對象傳遞給NUnit TestCase函數?
- 2. 將參數傳遞給NUnit測試
- 3. 從JUnitCore傳遞參數給Junit TestCase
- 4. NUnit TestCaseSource將值傳遞給工廠
- 5. 將數據傳遞給AppDelegate
- 6. 將數據傳遞給OnItemClickListener?
- 7. 將數據傳遞給dismissViewControllerAnimated
- 8. 將數據傳遞給DataGridViews
- 9. 將數據傳遞給uploadify
- 10. 將數據傳遞給secondViewController
- 11. 將數據傳遞給HttpModule
- 12. 通過命令行將參數傳遞給NUnit
- 13. 如何將列表作爲參數傳遞給nunit控制檯
- 14. 將AudioQueueBufferRef數據傳遞給FFT函數!
- 15. 將數據屬性傳遞給函數
- 16. 將總行數傳遞給數據表
- 17. 傳遞額外參數的TestCase設置
- 18. NUnit。將參數傳入拆卸方法
- 19. 將數據傳遞給Socket.io回調
- 20. 無法將數據傳遞給組件
- 21. 將數據傳遞給角2標籤
- 22. 將數據傳遞給$ _POST php
- 23. 將數據傳遞給委託
- 24. 通過UISegmentControl將數據傳遞給childViewControllers
- 25. 將數據從C傳遞給Java
- 26. 將數據傳遞給Singleton iOS
- 27. 將PHP數據傳遞給Nginx
- 28. 將PHP數據傳遞給ReactJS
- 29. 將數據值從HTML傳遞給JS
- 30. 如何將數據傳遞給方法
如果你這樣做, – 2013-04-22 15:16:26
我們不使用'nunit'來測試主機上的軟件,我們正在驗證一個微控制器平臺,因此我們需要例如計算機上的可用接口來連接到微控制器。 – Razer 2013-04-22 15:18:53
與運行集成測試的方式沒有多大區別。例如針對數據庫運行一些數據庫代碼。某處你有一個名稱,用戶名,密碼等配置文件。這可能會很痛苦,但它不是一個單元測試。 – 2013-04-22 15:30:37