I'm currently maintaining an "old" system written in C#.net, removing some obsolete features and doing some refactoring. Thanks god, the previous guy wrote some unit tests (MSTests). I quite comfortable with JUnit tests, but didn't do yet much with MSTests.
The test methods have a DeploymentItem
attribute, specifying a text file which is parsed by the business logic method that is being tested and a 2nd DeploymentItem
where just a path has been specified containing a bunch of TIF files that have to be deployed too.
[TestMethod()]
[DeploymentItem(@"files\valid\valid_entries.txt")]
[DeploymentItem(@"files\tif\")]
public void ExistsTifTest()
{
...
}
The tests worked before, but now I had to change the names of the TIF files contained in the \files\tif directory. According to a rule, the TIF filenames have to match a certain pattern which is also checked by the ExistsTifTest()
method.
Now I had to change the filenames in order to adapt them to the new requirements and suddently the TIF files are no more being deployed as before.
Can someone give me a hint why this happens or what may be the cause? The same thing happens also if I add a new text-file say "my2ndTest.txt" beside the "valid_entries.txt" in the \files\valid\ directory with the according DeploymentItem attribute on the test method. The file doesn't get deployed?
I got the images now deployed by defining the deployment path directly in the testrunconfig, but I'd like to understand why these things happen or why for instance my new file "my2ndTest.txt" doesn't get deployed while the others do.
Try this for VS2010. So you do not need to add DeployItems for every tif
Remove the
Add a test configuration.
- right-click on solution node in solution explorer
- Add -> New Item...
- Select Test Settings node on the left, select the item on the right
- Click Add
Call it eg
TDD
Choose
TDD
underTestMenu
>Edit Testsettings
.Click on the Deployment. Enable it and then Add the files and directories that you want.There will be a path relative to the solution. The files will be put on. The original file are for example here:
When I run my unit test it gets copied to
in testcode I call it from:
There is no need to choose Copy Always; put the files in the testproject; add hardcoded paths in the testcode. For me this solution worked best. I tried with DeploymentItem, copy always but it was not to my liking.
I've been working on this in VS2013. My findings to get this working:
A tip I also learned the hard way: do not forget to add this attribute to each individual test. The file copies on the first attributed test in the testrun, but remained missing when the order of the tests changed and non-attributed tests tried to find the file first.