2014-10-20 6 views
5

둘 이상의 인수와 함께 NUnit의 [TestCaseSource] 특성을 사용할 수 있습니까?MbUnit의 [Factory]와 같은 다중 인수가있는 NUnit의 [TestCaseSource]

당신이 볼
public IEnumerable<object[]> GetTestSwitchMultiItems() 
    { 
     yield return new object[] { SwitchType.Sell, 0.94733, 
            new SwitchSourceItem[] { new SwitchSourceItem(1176, 100, 50, SwitchSourceItem.QuantityType.TotalQuantity, SwitchType.Sell)}, 
            new SwitchEquivalentItem[] { new SwitchEquivalentItem(415318955, 35, 25, SwitchType.Buy), new SwitchEquivalentItem(4348, 65, 45, SwitchType.Buy) } }; 

     yield return new object[] { SwitchType.Sell, 0.94733, 
            new SwitchSourceItem[] { new SwitchSourceItem(1176, 100, 50, SwitchSourceItem.QuantityType.TotalQuantity, SwitchType.Sell)}, 
            new SwitchEquivalentItem[] { new SwitchEquivalentItem(415318955, 15, 25, SwitchType.Buy), new SwitchEquivalentItem(4348, 25, 45, SwitchType.Buy), 
                   new SwitchEquivalentItem(430397879, 20, 15, SwitchType.Buy), new SwitchEquivalentItem(5330, 20, 85, SwitchType.Buy)} }; 
    } 

    [Test, TestCaseSource("GetTestSwitchMultiItems")] 
    public void TestSwitchMultiItems(SwitchType switchType, double exchangeRate, SwitchSourceItem[] sources, SwitchEquivalentItem[] equivs) 
    { 
     ... 
    } 

, 매개 변수가 객체 []로 전달됩니다 TestSwitchMultiItems에 하나 개 이상의 매개 변수를 가질하기 위해 다음과 같습니다 (MbUnit에에서 마이그레이션되는) 내 코드입니다. 그게 작동해야합니까 아니면 대신 TestSwitchMultiItems (object [] 매개 변수)에서 하나의 매개 변수 만 사용해야합니다. 고맙습니다.

답변

7

예, 복수 인수와 함께 TestCaseSource 속성을 사용할 수 있습니다. 예를 들어, TestSwitchMultiItems 테스트가 두 번 실행되는 것을 볼 수 있습니다. 나는 다음의 인위적인 테스트 코드에 NUnit을 사용했다. TestSwitchMultiItems이 두 번 실행되고 각 테스트에서 간단한 Assert 호출이 성공합니다.

[Test, TestCaseSource("GetTestSwitchMultiItems")] 
    public void TestSwitchMultiItems(string switchType, double exchangeRate, object[] sources, object[] equivs) 
    { 
     Assert.AreEqual("Sell", switchType); 
    } 

    public IEnumerable<object[]> GetTestSwitchMultiItems() 
    { 
     yield return 
      new object[] 
      { 
       "Sell", 0.94733, new object[] { new { a = 1176, b = 100, c = 50, d = 5, e = "Sell" } }, 
       new object[] { new { a = 415318955, b = 35, c = 25, d = "Buy", e = 4348, f = 65, g = 45, h = "Buy" } } 
      }; 

     yield return 
      new object[] 
      { 
       "Sell", 0.94733, new object[] { new { a = 1176, b = 100, c = 50, d = 5, e = "Sell" } }, 
       new object[] 
       { 
        new { a = 415318955, b = 35, c = 25, d = "Buy", e = 4348, f = 65, g = 45, h = "Buy" }, 
        new { a = 415318955, b = 35, c = 25, d = "Sell", e = 7348, f = 65, g = 45, h = "Sell" } 
       } 
      }; 
    }