2010-07-06 113 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

相關問題