使用nunit控制台通过测试用例参数 [英] pass test case parameters using nunit console

查看:109
本文介绍了使用nunit控制台通过测试用例参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Nunit 数据驱动的测试方法来开发测试。我有2个参数的测试方法:xlsx文件的路径和工作表名称。
当我在 TestCase 属性中传递参数时,例如在我要运行3个测试用例时,必须在其中编写如下代码: p>

I am developing tests using Nunit and data driven testing approach. I have test method with 2 parameters: path to xlsx file and worksheet name. It works perfect in Visual Studio when I pass parameters in TestCase attribute, for example when I want to run 3 test cases have to write something like this:

[TestCase(@"pathToFile.xlsx", "TestCase1")]
[TestCase(@"pathToFile.xlsx", "TestCase2")]
[TestCase(@"pathToFile.xlsx", "TestCase3")]
public void performActionsByWorksheet(string excelFilePath, string worksheetName)
{    
    //test code
}

我想运行测试用例并使用 Nunit Console (不要在代码中写入参数)。

I would like to run my test cases and pass parameters using Nunit Console (not to write parameters in code).

有可能实现吗?

推荐答案

如果使用NUnit 3可以使用TestContext.Parameters属性:

If you are using NUnit 3 you can use TestContext.Parameters property:

[Test]
public void performActionsByWorksheet()
{
    string excelFilePath = TestContext.Parameters["excelFilePath"];
    string worksheetName = TestContext.Parameters["worksheetName"];
    TestContext.WriteLine(excelFilePath);
    TestContext.WriteLine(worksheetName);
}

和--params命令行参数:

and --params command line argument:

nunit3-console.exe path/to/your/test.dll --params=excelFilePath=testPath;worksheetName=testName

这篇关于使用nunit控制台通过测试用例参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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