I'm new with unit testing in visual studio and I want to load a physical xml file. This file is in the unit testing project as a Content and it's copied in the output directory.
So, when I compile the project, the xml file is in the output directory. But when I execute the test, a new directory is created with all dependent DLL, but the xml file isn't copied.
The content of the Xml is needed to execute the test. I execute this code to retrieve the path of the Xml file in the execution folder :
private static string GetXmlFullName()
{
// GetApplicationPath use the current DLL to find the physical path
// of the current application
string executeDirectory = AssemblyHelper.GetApplicationPath();
return Path.Combine(executeDirectory, "content.xml");
}
The exception is :
System.IO.DirectoryNotFoundException: 'd:\***\solutiondirectory\testresults\*** 2012-06-13 17_59_53\out\content.xml'.
How can I add this file in the execute folder?
Thanks in advance. (and sorry for my english ...)
Where to put test files. Unit tests run against specific lines of code. So it makes sense to place them right next to that code. Integration tests run against many lines of code in many files.
A unit test is a way of testing a unit - the smallest piece of code that can be logically isolated in a system. In most programming languages, that is a function, a subroutine, a method or property. The isolated part of the definition is important.
For file upload related testing we need to Mock HTTPContext, HTTPContext. Server and HttpPostedFileBase. These classes handle the file uploading and saving.
You need to place a DeploymentItemAttribute on the test class.
For example to include all files in the Data folder
[TestClass()]
[DeploymentItem("Data")]
public class MyTestClass
{
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With