Wrong.
Here is the part of the code that was causing the problem - two lines that I've written in applications, a hundred times before without any issue.
XmlDocument testXmlDocument = new XmlDocument();
testXmlDocument.Load(@".\TestXml\SWHNewFormat.xml");
But when the test ran, it threw the following errorSystem.IO.DirectoryNotFoundException: Could not find a part of the path 'D:[Path to test project]\bin\Debug\TestXml\SWHNewFormat.xml'.
Turns out that when you run your tests they are deployed to a folder (the path of which is configurable). Any files you want to be deployed with the tests (for example xml files which your tests may need to read) have to be flagged up on the test method (or test class) with the DeploymentItem attribute.
Finding that out was the easy part. Actually getting the fire to deploy to the folder was another matter.
Google. Rinse. Repeat.
Firstly, in Visual Studio I had to set the "Copy to Output Folder" property to "Copy Always" on the files I wanted to deploy with your my tests. Once that was set I then needed to set the DeploymentItem attribute.
The attribute accepts two parameters. The first is the path to the folder that contains the file(s) you want to deploy and the second is optional and the name of the folder that will be created in the deployed folder.
But with both parameters set on the attribute, still my file did not appear in the deploy folder.
Gotcha!
- @".\XmlMangerTests\TestXml"
- "D:[Path to test project]\bin\Debug\XmlMangerTests\TestXml"
- "TestXml"
- D:\[Path to Solution]\TestResults\Deploy_CompName 2012-10-25 11_10_16\Out\TestXml