MS Test: Getting executing testlocation?

天大地大妈咪最大 提交于 2019-12-08 14:35:28

问题


How do I find the equivalent of a path to the executing assembly when running tests under MS Test in VS 2010? I need to know where the test is running from, so that I can set a relative path to a data file that it needs.

I am trying to find the same sort of path to an executing test that I would get if I used System.Reflection.Assembly.GetEntryAssembly().Location on an executing assembly. Thanks for your help.


回答1:


You can use TestContext.DeploymentDirectory to get the test deployment directory. The test configuration allows you to automatically deploy files for tests.




回答2:


This question is not specific to MsTest. You can use the same solution you would use in any other .NET application.

An answer from a similar question:

string directory = AppDomain.CurrentDomain.BaseDirectory;



回答3:


Just get the assembly for the current test.

See How to get the assembly (System.Reflection.Assembly) for a given type in .Net?



来源:https://stackoverflow.com/questions/5710167/ms-test-getting-executing-testlocation

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