Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9125571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:50:06+00:00 2026-06-17T06:50:06+00:00

I have an application that has many unit tests in many classes. Many of

  • 0

I have an application that has many unit tests in many classes. Many of the tests have DeploymentItem attributes to provide required test data:

[TestMethod]
[DeploymentItem("UnitTesting\testdata1.xml","mytestdata")]
public void Test1(){
    /*test*/
}

[TestMethod]
[DeploymentItem("UnitTesting\testdata2.xml","mytestdata")]
public void Test1(){
    /*test*/
}

When tests are run individually, they pass. When all are run at once (For example, when I select “Run all tests in the current context”), some tests fail, because the DeploymentItems left behind by other tests cause the tests to grab the wrong data. (Or, a test incorrectly use the files meant for another test that hasn’t run yet.)

I discovered the [TestCleanup] and [ClassCleanup] attributes, which seem like the would help. I added this:

[TestCleanup]
public void CleanUp(){
    if(Directory.Exists("mytestdata"))
        Directory.Delete("mytestdata", true);
}

The trouble is, this runs after every test method, and it seems that it will delete DeploymentItems for tests that have not run yet. [ClassCleanup] would prevent this, but unfortunately, it would not run often enough to prevent the original issue.

From the MSDN documentation, it seems that DeploymentItem only guarantees that the files will be there before the test executes, but it is not more specific than that. I think I am seeing the following problem:

  1. Deployment Item for test executes
  2. (other stuff happens?)
  3. Test cleanup from previous test executes
  4. Next test executes
  5. Test fails because files are gone

Does anyone know the execution order of the different test attributes? I’ve been searching but I haven’t found much.

I have thought about having each deployment item use its own, unique folder for data, but this becomes difficult as there are hundreds of tests to go through.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:50:07+00:00Added an answer on June 17, 2026 at 6:50 am

    The order of the test attributes are as follows:

    1. Methods marked with the AssemblyInitializeAttribute.
    2. Methods marked with the ClassInitializeAttribute.
    3. Methods marked with the TestInitializeAttribute.
    4. Methods marked with the TestMethodAttribute.

    Part of the problem is that Visual Studio runs tests in a non-deterministic order(by default but this can be changed) and multiple at a time. This means that you cannot delete the folder after each test.


    In general, if you can avoid going to the disk for unit tests it will be much better. In general you don’t want to have anything besides code that can break your tests.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that has many threads processing data. As part of this
We have an old asp.net application that has no unit tests, integration tests, component
I have a multithreaded application that has many concurrent operations going on at once.
I am creating a web application that will have many users. Each user has
I have an application that has many users who can login and perform insertion,
I have an application that depends on connection It has many Activities.I need to
I have an application that has many views (Using tab bar controller). I want
I have an application that has a GUI thread and many different worker threads.
I'm developing an Android application that has many activities. I have a Logout Activity
I have a Delphi application that has many dependencies, and it would be difficult

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.