obtain command line arguments in unit test

天涯浪子 提交于 2019-12-13 16:25:56

问题


In a Test project in Visual Studio 2008 (Pro), I created a Test project, and I want to configure the project properties to give a command line argument to the tests. I set the properties, but then realized I have no idea how to actually use the argument.

How do you get the arguments from MSTest?


回答1:


VS 2008 test are compiled into DLLs which can't directly receive command line arguments as far as I know.

You could add a configuration file 'app.config' for the dll and use that instead.

Just beware, mstest only copies .config files for the test container being run at the time.

if you have the following...

mytest.dll
mytest.dll.config
lib.dll
lib.dll.config

and you reference lib.dll from mytest.dll, when you run the tests lib.dll.config will not get copied and your test may fail because of this.




回答2:


Perhaps you can use GetCommandLine().

Edit: GetCommandLine() is a win32-function, but there ought to be a corresponding .Net function for it.



来源:https://stackoverflow.com/questions/181354/obtain-command-line-arguments-in-unit-test

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!