消息:没有提供参数 - 动态数据参数nunit,c#.visual studio [英] Message: no arguments were provided -dynamic data parameters nunit, c#.visual studio

查看:94
本文介绍了消息:没有提供参数 - 动态数据参数nunit,c#.visual studio的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

帮助!!!!



我需要帮助,因为我无法看到我没有参加Nunit参数化测试的地方。我正在获得错误'没有参数提供'



我尝试过:



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:

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

推荐答案

我已经将类/方法的角色混淆了。现在已经有一段时间了,因为我使用NUnit所以请耐心等待。



你需要的是你的数据来源。您决定使用自己的类来封装测试数据。请注意,您不能将任何参数传递给此方法,因此您需要提供一些其他方法来获取XmlNode。

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.
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):

public static IEnumerable ReturnValuesToTest()
{
  foreach (XmlNode node in node3)
    foreach (string Browser in browsers)
      yield return new [] {username,password,browser};
}



现在使用BrowserTesting类,你的测试方法必须有一个匹配的参数。


Now using the BrowserTesting class your test method must have a matching parameter.

[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:

[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:

[Test]
[TestCaseSource(typeof(MyClassThatHasReturnValuesToTestMethod),"ReturnValuesToTest")]
public static void BrowserTest(string User, string Password, string Browser)
{
  // do the test here
}



你绝对不想要的是从BrowserTesting构造函数调用TestBase.BrowserTest()。 NUnit会自动为每个测试数据实例调用测试方法。



我建议你对 TestCaseSource属性 [ ^ ]和 TestCaseData [ ^ ]。你可以用后者做一些漂亮的事情。


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.


这篇关于消息:没有提供参数 - 动态数据参数nunit,c#.visual studio的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆