2014-10-20 2 views

ответ

2

Я не использовал MbUnit, но самое близкое к DynamicTestFactory, что я знаю в NUnit, это TestCaseSource.

Я нашел этот пример DynamicTestFactory (от here):

[DynamicTestFactory] 
public IEnumerable<Test> Should_Create_And_Execute_Dynamic_Tests() 
{ 
    IEnumerable<int> list = new[] {1, 2, 3, 4, 5}; 
    foreach (int i in list) 
    { 
     yield return new TestCase(string.Format("Test {0}",i), 
     () => { Assert.IsTrue(MyFunction(i)); }); 
    } 
} 

Это, как вы будете использовать NUnit-х TestCaseSource (см here), чтобы сделать то же самое:

[Test, TestCaseSource("SourceList")] 
    public void MyFunctionTest(int i) 
    { 
     Assert.IsTrue(MyFunction(i)); 
    } 

    private static readonly IEnumerable<int> SourceList = new[] { 1, 2, 3, 4, 5 }; 
Смежные вопросы