.NET: getting absolute path for a file when running VS Team Test

I currently have a test class TestClass.cs in C: \ Projects \ TestProject \ TestClass.cs
I also have an Xml file in C: \ Projects \ TestProject \ config \ config.xml

In TestClass.cs, I have a test method for loading Xml from the file system as follows:

XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(Path.Combine(Assembly.GetExecutingAssembly().Location, "config\config.xml"));

Unfortunately, the Location property gives me the value:
C: \ Projects \ TestProject \ TestResults \ klaw_ [computernamehere] [time here] \

instead of what I want is C: \ Projects \ TestProject \

I tried Assembly.GetExecutingAssembly (). CodeBase also with similar results.

Any ideas?

+3
source share
4

DeploymentItemAttribute, MSTest. , DLL.

+2

, ? :

Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resource);

+ . , :

AssemblyGetExecutingAssembly().GetManifestResourceNames();

.

+2

, . NUnit/TestDriven.NET .. - MSTest . () - , ([DeploymentItem]), testrunconfig ( → → ...).

TestDriven.NET, " ".

+1
source

In addition to labeling the item with [DeploymentItem], you also need to make sure that your test version of the configuration includes "Enable Deployment" along with a directory where you can get items.

+1
source

Source: https://habr.com/ru/post/1705452/


All Articles