2010-07-06 152 views
28

是否可以通过命令行将值传递给NUnit测试?我的测试使用特定的URL。我在不同的URL上有不同的代码实例,并希望通过命令行指定URL。 App.config不是一个选项,因为我想通过批处理文件为不同的URL运行测试。通过命令行将参数传递给NUnit

+0

您是否尝试过使用Environment.GetCommandLineArgs?那工作? http://msdn.microsoft.com/en-us/library/system.environment.getcommandlineargs.aspx – Paddyslacker 2010-09-01 19:38:32

回答

2

目前似乎没有解决方案。最好的选择是使用NUnit项目文件,修改那里的设置并将解决方案文件传递给跑步者。

26

环境变量。

使用来自命令行的set或使用来自nant的<setenv>。然后使用Environment.GetEnvironmentVariable()读取该值。

0

我有类似的问题,阿希姆的回答让我在正确的轨道上,对其他读者

创建这样像example.nunit文件:

<NUnitProject> 
    <Settings activeconfig="local"/> 
    <Config name="local" configfile="App.config"> 
    <assembly path="bin\Debug\example.dll"/> 
    </Config> 
    <Config name="dev" configfile="App.Dev.config"> 
    <assembly path="bin\Debug\\example.dll"/> 
    </Config> 
    <Config name="test" configfile="App.Test.config"> 
    <assembly path="bin\Debug\\example.dll"/> 
    </Config> 
</NUnitProject> 

所有文件/路径(config和assembly文件的路径)与nunit文件的位置有关。另外App.config,App.Dev.config等只是.net配置文件。

下一页当你wanne运行它一定的配置你执行像这样

nunit3-console.exe example.nunit /config:test 

更多关于NUnit的文件的格式信息https://github.com/nunit/docs/wiki/NUnit-Project-XML-Format有关命令行参数

更多信息 http://www.nunit.org/index.php?p=consoleCommandLine&r=2.2.5

+0

@Achim尝试通过在nunit文件中添加configs来执行上述方法,但会抛出错误消息 - 无法定位Fixture。 \ nunit-console-x86.exe $ env_config/config:CI/run:$ feature $ dll_dir/result = $ result_dir – ReuseAutomator 2016-11-29 00:29:15

+0

@Marteen Kieft你能帮我解决上述问题吗我正面临 – ReuseAutomator 2016-11-29 00:32:21

+0

@ReuseAutomator:在你的项目中,没有特定的配置设置。你实际上可以在没有这个配置设置的情况下直接运行你的测试,执行:nunit3-console.exe mytest.dll 你可能会得到相同的错误,所以你可能想要检查: 你的测试类是否有testfixture属性 使用Public开始你的课程(如此公开mytestclass {..}而不是只有课程(没有公开)。如果你仍然面对它,请在这里创建一个问题并指向我:) – 2016-12-02 08:42:42

相关问题