Invalid number of arguments provided in nunit

Developed a test file with Testcasesource in selenium using C #. After running a test case in NUnit, it shows the error as "Invalid number of arguments." And this is my test code

[TestFixture]
class testcases 
{

   static String[] exceldata= readdata("Inputdata.xls", "DATA", "TestCase1");


    [SetUp]
    public void Setup()
    {
        //setupcode here

    }
   [Test, TestCaseSource("exceldata")]
    public void Sample (String level,String Username,String password,String FirstName)
    {
       //testcase code here

    }

    [TearDown]
    public void TearDown()
    {
        tstlogic.driverquit();
    }

4 values ​​are retrieved and I can see the values ​​in NUnit. But it shows an error like "Wrong number of arguments." Can anyone help?

+3
source share
1 answer

The method labeled TestCaseSource should return a bunch of "TestCases" - where each TestCase is a set of inputs required by the test method. Each test input-set in your case should have 4 string parameters.

TestCaseSource [], 4 . .

[Test, TestCaseSource("DivideCases")]
public void DivideTest(int n, int d, int q)
{
    Assert.AreEqual( q, n / d );
}

static object[] DivideCases =
{
    new object[] { 12, 3, 4 },
    new object[] { 12, 2, 6 },
    new object[] { 12, 4, 3 } 
};

, , testCaseSource 4 . NUnit 4 -, . 4 = > , .

. , DivideCases

private static int[] DivideCases = new int[] { 12, 3, 4 };  // WRONG. Will blow up
+6

All Articles