运行单元测试时如何获取目录 [英] How to get Directory while running unit test
问题描述
说我有一个名为MyProject的测试项目,我想要获取我的项目正在运行的目录来检索文件。 。测试我运行:
AppDomain.CurrentDomain.SetupInformation.ApplicationBase
,我收到C:\\\Source\\MyProject.Test\\bin\\Debug / code>。
这跟我以后接近。我不想要 bin \\\Debug
部分。
任何人都知道如何可以得到C:\\\Source\\MyProject.Test\\
?
我会这样做。
我建议将该文件作为解决方案/项目的一部分。然后右键单击 - >属性 - >复制到输出=永远复制。
然后,该文件将被复制到您的输出目录(例如C:\Source \MyProject.Test\bin\Debug)。
Hi when running my unit test I'm wanting to get the directory my project is running in to retrieve a file.
Say I have a Test project named MyProject. Test I run:
AppDomain.CurrentDomain.SetupInformation.ApplicationBase
and I receive "C:\\Source\\MyProject.Test\\bin\\Debug"
.
This is close to what I'm after. I don't want the bin\\Debug
part.
Anyone know how instead I could get "C:\\Source\\MyProject.Test\\"
?
I would do it differently.
I suggest making that file part of the solution/project. Then right-click -> Properties -> Copy To Output = Copy Always.
That file will then be copied to whatever your output directory is (e.g. C:\Source\MyProject.Test\bin\Debug).
这篇关于运行单元测试时如何获取目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!