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?
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