3

Developed testcase with Testcasesource in selenium using c#. After running the test case in the NUnit, It shows the error as "Wrong Number of arguments provided". And this is my test case 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();
    }

The 4 values are retrieved and i can see the values in NUnit. But it shows the error as "Wrong number of arguments provided". Can anyaone please help?

Michael Dunlap
  • 4,300
  • 25
  • 36
  • Replacing call to some magical `ReadData` function with static array will make the sample much more useful for reproducing/demonstrating the problem. So far it is your word vs. NUnit runtime error - honestly I'd trust more to errors from well know tools than anyone's (including my own) word. – Alexei Levenkov Feb 06 '14 at 05:02
  • written the readdata method in my logic and i call this method here. – Nithya Iyappan Feb 06 '14 at 05:18
  • and my read data code is – Nithya Iyappan Feb 06 '14 at 05:19
  • public static String[] readdata(String filename, String sheetname, String tablename) { String[] data_from_excel; //code here return data_from_excel; } – Nithya Iyappan Feb 06 '14 at 05:20

1 Answers1

6

The method marked as TestCaseSource is supposed to 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 must have 4 string params.

So the TestCaseSource method should be returning an object[] which contains internal 4 member arrays. See the following example

[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 } 
};

In your case, I think your testCaseSource method is returning 4 strings. NUnit reads this as 4 input-param-sets.. each containing one string. Attempting to call the parameterized test method with 4 params with one string => the error you are seeing.

E.g. you can reproduce your error by setting DivideCases like this

private static int[] DivideCases = new int[] { 12, 3, 4 };  // WRONG. Will blow up
Gishu
  • 134,492
  • 47
  • 225
  • 308
  • Now i make it as public public static String[] exceldata = readdata("C:\\Users\\Indium\\Documents\\Visual Studio 2010\\Projects\\CHS\\CHS\\Data\\Inputdata.xls", "DATA", "TestCase1"); – Nithya Iyappan Feb 06 '14 at 05:24
  • yeah. NUnit read the return values as 4 input param sets. thank you – Nithya Iyappan Feb 06 '14 at 05:33