在单元测试中获取命令行参数 [英] obtain command line arguments in unit test

查看:81
本文介绍了在单元测试中获取命令行参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Visual Studio 2008(Pro)的一个Test项目中,我创建了一个Test项目,并且我想配置项目属性以为测试提供命令行参数.我设置了属性,但随后意识到我不知道如何实际使用该参数.

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.

如何从MSTest获取参数?

How do you get the arguments from MSTest?

推荐答案

VS 2008测试已编译为DLL,据我所知,这些DLL无法直接接收命令行参数.

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

您可以为dll添加一个配置文件"app.config",并改为使用该文件.

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

请注意,mstest仅复制当时正在运行的测试容器的.config文件.

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

并且您从mytest.dll中引用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.

这篇关于在单元测试中获取命令行参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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