Here is how I am trying to access the file-
I added a folder "TestData" in my unit test project
Added a file via Add->Existing Item. Set the Build Action=None, Copy To Output Directory= Copy Always
Accessing the file in the unit test method as below-
string fileName = System.IO.Path.Combine(
System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetExecutingAssembly().Location), "TestData\\TestExcel2007File1.xlsx");
XmlDocument actual;
actual.Load(fileName); //Throws exception saying cannot find part of the file path
I also tried using the Method attribute as-
[TestMethod, DeploymentItem(@"Test Data\", @"Test Data\")]
None seems to work.
The file path generated is
"D:\\MyProject\\TestResults\\MACHINE_NAME 2015-01-23 05_21_45\\Out\\TestData\\Excel2007TestData.xlsx"
And the Out folder does not have the TestData folder, or the Excel file.
Aucun commentaire:
Enregistrer un commentaire