【发布时间】:2017-06-05 12:18:19
【问题描述】:
我在从 nunit3-console 执行测试时遇到问题。我需要将参数传递给 TestFixture 构造函数,但我想调用特定的测试。 在我的夹具中,我有两个不同的构造函数和一个没有参数的方法。现在我称之为 cdm:
- nunit3-console --params username=u1;password=p1 --test namespace.class.Test1 Tests.dll
我想,现在 nunit 尝试将这 2 个参数传递给我的测试,但我想将它传递给具有
的构造函数- [TestFixtureSource(typeof(TestFixtureSource), "GetParameters")]
当我使用 --where "class='TestFixtureClassName'" 调用 cmd 时,子句参数被传递到 testfixture 构造函数中,但它会在此夹具内运行所有测试。
举例
namespace TestNamespace
{
[TestFixtureSource("GetTestFixtureSource")]
public class TestFixture
{
private int _a;
private int _b;
TestFixture()
{
_a = 8;
_b = 10;
}
TestFixture(int a, int b)
{
_a = a;
_b = b;
}
[Test]
public void Test()
{
//test1 body
}
[Test]
public void Test2()
{
//test2 body
}
[Test]
public void Test3()
{
//test3 body
}
}
}
现在在命令提示符下,我调用了这一行:
- nunit3-console --params a=80;b=100 --test TestNamespace.TestFixture.Test Tests.dll
这一行的结果是 selenium 尝试使用 2 个参数查找方法 Test。但是当你像这样调用 nunit-console 时:
- nunit3-console --params a=80;b=100 --where class='TestFixture' Tests.dll
它会找到带有 2 个参数的合适构造函数并调用它,但会在此 Fixture 中运行所有测试。 现在,我想要实现的是运行单个测试,但将 --params 传递给 TestFixture 的合适构造函数。
希望现在我为您更清楚地介绍了它。
【问题讨论】:
-
您是否有理由要使用参数而不是 app.config 文件来执行此操作?
-
我在没有参数的情况下从 Visual Studio 运行此测试,但它们也由 TestComplete 中的 cmd 在两个不同的数据库、两个不同的 url 上运行(它们为每个用户个性化)
标签: c# selenium selenium-webdriver nunit nunit-console