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 6014479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:41:53+00:00 2026-05-23T02:41:53+00:00

I need to enforce TestClass order when executing tests with MSTest. The order of

  • 0

I need to enforce TestClass order when executing tests with MSTest.

The order of TestClasses and tests within each class can be random, but MSTest should not pick a test from another TestClass until it is done executing ClassInitialize, all tests in the class, and ClassCleanup.

I have global AssemblyInitialize and AssemblyCleanup, therefore the following does not work, because it initializes the assembly for each test:


MSTest.exe /testcontainer:MyUnitTests.dll /resultsfile:report.trx /test:TestClass1 /test:TestClass2
  • 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-05-23T02:41:54+00:00Added an answer on May 23, 2026 at 2:41 am

    I asked a similar question here, though it was not about test class execution order. Ordering tests can cause them to be brittle if the reason for the ordering is so that some sort of state can be setup/maintained. If this is the case with your tests, I would suggest instead writing them in a way that would be order-agnostic.

    As regards your problem with the assembly-level code, a work around for the AssemblyInitialize and AssemblyCleanup can be as follows:

    private int InitCount;
    
    [AssemblyInitialize]
    public static void Setup(TestContext context)
    {
         if (InitCount++ == 0) {
             //Do Something
         }
    }
    
    [AssemblyCleanup]
    public static void Teardown()
    {
          if (--InitCount == 0) {
              //Do something
          }
    }
    

    Basically, you can force the assembly-level methods to fire only once.

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

Sidebar

Related Questions

I need a little help on how I can enforce the following constraints on
I need to make a base class enforce this: public class DialogForm : Form
I have a situation where i need to enforce a unique constraint on a
Need some help about with Memcache. I have created a class and want to
I need to enforce a composite key at the database level . The composite
To enforce the create-drop hibernate option I need to shutdown tomcat(?), however if I
I have some relative links on my site that need to enforce https even
I have built an XML-RPC interface in Python and I need to enforce some
I need to define an Interface which has to enforce certain operator overloading to
I need to write a function that accepts an object , but I want

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.