2016-10-26 7 views
1

関数を再度コピーして貼り付けるのではなく、1回のテストで複数のパラメータを使用する方法はありますか? C#のためのNUnitでJS単位テストは、異なるパラメータで複数回実行されます

例:私はJsの中で欲しい

[TestCase("0", 1)] 
[TestCase("1", 1)] 
[TestCase("2", 1)] 
public void UnitTestName(string input, int expected) 
{ 
    //Arrange 

    //Act 

    //Assert 
} 

describe("<Foo />",() => { 

    [TestCase("false")] 
    [TestCase("true")] 
    it("option: enableRemoveControls renders remove controls", (enableRemoveControls) => { 
     mockFoo.enableRemoveControls = enableRemoveControls; 

     //Assert that the option has rendered or not rendered the html 
    }); 
}); 
+0

新しい機能を作り、それを呼び出すだけです。一般に、コールバックを 'it'(と' describe'など)に渡すので、コールバックを返す関数を作ることができます。 'function makeTest(input、expected){return function(){assert(input ==あなたがテストで 'it(" passed "、makeTest(1,1))'を呼び出すと 'それは失敗します(makeTest(" apple "、" orange ")) ' – vlaz

答えて

2

あなたが関数内it -callを入れて、異なるパラメータでそれを呼び出すことができます。

describe("<Foo />",() => { 

    function run(enableRemoveControls){ 
     it("option: enableRemoveControls renders remove controls",() => { 
      mockFoo.enableRemoveControls = enableRemoveControls; 

      //Assert that the option has rendered or not rendered the html 
     }); 
    } 

    run(false); 
    run(true); 
}); 
関連する問題