在单元测试中获取命令行参数

发布于 2024-07-08 00:21:21 字数 131 浏览 7 评论 0原文

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

如何从 MSTest 获取参数?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

相思碎 2024-07-15 00:21:21

据我所知,VS 2008测试被编译成DLL,不能直接接收命令行参数。

您可以为 dll 添加配置文件“app.config”并使用它。

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

如果您有以下内容...

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

并且您从 mytest.dll 引用 lib.dll,则当您运行测试时,lib.dll.config 将不会被复制,并且您的测试可能会因此失败。

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.

终弃我 2024-07-15 00:21:21

也许您可以使用 GetCommandLine()。

编辑: GetCommandLine() 是一个 win32 函数,但应该有一个相应的 .Net 函数。

Perhaps you can use GetCommandLine().

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文