locked
Intermittent issue with DeploymentItem attribute not copying folder RRS feed

  • Question

  • I have a suite of c# / mstest unit tests that I run in VS2019.  Many of the tests have a DeploymentItem attribute that copies a folder of test files to the current test folder. 

    [TestMethod] [DeploymentItem("TestFiles", "TestFiles")] public void Validate_OutputFile() { string prefix = "test"; string fileNameAfterProcess = "test.1.tif"; IStreamObject streamObject = new StreamObject(); streamObject.FileName = "sample.tif"; string path = Path.Combine(TestContext.TestDeploymentDir, "TestFiles", "1.TIF"); FileInfo originalFile = GetFileInfo(path); //FileNotFoundException on the following line when running all tests for the solution

    using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read)) { . . .


    When I run the test in isolation, the testfiles folder is correctly deployed and the test passes... When I run all 300 tests in the solution, the testfiles folder does not get deployed and the test fails with FileNotFoundException when file read attempt occurs.

    Why does this work in isolation but not when I run all tests for the solution?

    Monday, March 2, 2020 4:26 PM

All replies

  • Hi scott_m,

    Thank you for posting here.

    If you run all 300 tests, unit test will run your tests multi-threaded, and if you run the test in isolation, the tests will be forced to run every single-thread.

    Since you have a suite of unit tests, please note that UNIT Tests have no dependency on each other(There is no order to them).

    The sequence of execution, or the possibility that shared resources might have already been instantiated(or being in the process of instantiation) by another tests running in parallel.(You could refer more/similar issues here: MSTest tests succeed if run in isolation, fail if run with other tests and Unit Testing – dependent tests)

    Hope all above could help you a little.

    Kind Regards,

    Tianyu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, March 3, 2020 7:40 AM
  • Hi Tianyu, no dependencies between the tests.    Feels like a possible issue with the way I am using DeployItem attribute with a subfolder along with using TestContext.TestDeploymentDir to read the deployed file.  Works fine in isolation... Blows up when run as a group.

    Tuesday, March 3, 2020 3:53 PM
  • Hi scott_m,

    Thank you for your feedback.

    If possible, when you run tests as a group, you could try to print out the entire directory of the file and check if this directory is correct.

    Hope this could help you.

    Kind Regards,

    Tianyu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, March 5, 2020 5:36 AM
  • Hi scott_m,

    Sorry to bother you.

    According to your description, did you click "Run All Test" in the test explorer? If so, I'm afraid that your tests are not performed in the specified order.

    You can create a ordered test for your tests, please refer: How to: Create an Ordered Test.

    Any feedback will be expected.

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Wednesday, March 11, 2020 7:41 AM