Click here to Skip to main content
15,888,065 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
HELP!!!!

I need help as I cannot see where Iam falling short of Nunit parameterised tests.I am getting an error ' no arguments provided'

What I have tried:

C#
[Setup]
public static IEnumerable ReturnValuesToTest(XmlNode node3)
{
  foreach (XmlNode node in node3)
  {
    //this gets the username and Password from the xml node
    foreach (string Browser in browsers)
    {
      //loops through repository of browsername....
      yield return new BrowserTesting(username,password,browser);
      // returns values to constructor.
    }
  }
}

public class BrowserTesting
{
  private string newuser;
  private string newpassword;
  private string newbrowser;

  public BrowserTesting(string newuser, string newpassword, string newbrowser)
  {
    this.newuser = newuser;
    this.newpassword = newpassword;
    this.newbrowser = newbrowser;
    TestBase.BrowserTest(this.newuser, this.newpassword, this.newbrowser);
    // call the Testmethod accepting parameters 
  }
}

[Test]
[TestCaseSource(typeof(BrowserTesting),"BrowserTesting")]
public static void BrowserTest(string User, string Password, string Browser)
{
  // pull up the url in different browsers with the same User and password parameter.
}
Posted
Updated 27-Jun-18 0:20am
v2
Comments
Richard MacCutchan 26-Jun-18 12:41pm    
Where does this error occur?

1 solution

I have got the roles of the classes/methods mixed up. Now it's a while since I used NUnit so bear with me.

What you need is a source of your data. You decided to use your own class to encapsulate the test data. Please note that you cannot pass any parameter to this method so you need to come up with some other way to get the XmlNode.
C#
public static IEnumerable ReturnValuesToTest()
{
  foreach (XmlNode node in node3)
    foreach (string Browser in browsers)
      yield return new BrowserTesting(username,password,browser);
}

Alternatively you could simply return a string array (one item per parameter):
C#
public static IEnumerable ReturnValuesToTest()
{
  foreach (XmlNode node in node3)
    foreach (string Browser in browsers)
      yield return new [] {username,password,browser};
}

Now using the BrowserTesting class your test method must have a matching parameter.
C#
[Test]
[TestCaseSource("ReturnValuesToTest")]
public static void BrowserTest(BrowserTesting browserTesting)
{
  // do the test here
}

If you choose to use the string[] as source of your data then, your test method signature stays as it was:
C#
[Test]
[TestCaseSource("ReturnValuesToTest")]
public static void BrowserTest(string User, string Password, string Browser)
{
  // do the test here
}

Both above examples assume that your data source method is in the same class as the test method. If it isn't then you need to specify it explicitly:
C#
[Test]
[TestCaseSource(typeof(MyClassThatHasReturnValuesToTestMethod),"ReturnValuesToTest")]
public static void BrowserTest(string User, string Password, string Browser)
{
  // do the test here
}

What you definitely don't want is to call TestBase.BrowserTest() from BrowserTesting constructor. The test method is called automatically for each instance of the test data by NUnit.

I recommend you to do some reading on TestCaseSource Attribute[^] and TestCaseData[^]. You can do some pretty things with the latter.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900