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

  • SEARCH
  • Home
  • 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 6330045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:47:34+00:00 2026-05-24T17:47:34+00:00

This question regards unit testing in Visual Studio using MSTest (this is important, because

  • 0

This question regards unit testing in Visual Studio using MSTest (this is important, because of MSTest’s execution order). Both the method marked [TestInitialize] and the test class constructor will run before each test method.

So, the question is, what do you tend to do in each of these areas? Do you avoid performing certain activities in either? What is your reason: style, technical, superstition?

  • 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-24T17:47:35+00:00Added an answer on May 24, 2026 at 5:47 pm

    The constructor is just a structure provided by the language. Every test framework seems has its own controlled lifecycle “initialize”. You’ll probably only get into trouble using the constructor to mutate your locals.

    MSTest: You get an entire new instance of the test class for every TestMethod. This might be the only case where it’s ok to mutate your locals in the constructor, initializer, or test method and not affect the other test methods.

    public class TestsForWhatever
    {
        public TestsForWhatever()
        {
            // You get one of these per test method, yay!
        }
    
        [TestInitialize] 
        public void Initialize() 
        {
            // and one of these too! 
        }
    
        [TestMethod]
        public void AssertItDoesSomething() { }
    
        [TestMethod]
        public void AssertItDoesSomethingElse() { }
    }
    

    MSpec: You only get one Establish and Because for all your assertions (It). So, don’t mutate your locals in your assertions. And don’t depend on mutations of locals in base contexts (if you use them).

    [Subject(typeof(Whatever))]
    public class When_doing_whatever
    {
        Establish context = () => 
        { 
            // one of these for all your Its
        };
    
        Because of = () => _subject.DoWhatever();
    
        It should_do_something;
        It should_do_something_else;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I bumped into an additional question that I needed in regards to this: Using
I'm late to the party with regards to using unit testing... trying to figure
This question is in regards to this blog entry. https://blog.stackoverflow.com/2008/07/easy-background-tasks-in-aspnet/ All the way at
I have just asked this question an hour ago but with regards to IE8
I had posted a question in regards to this code. I found that JTextArea
I'm pretty sure this is a simple question in regards to formatting but here's
Disclaimer, I not do anything in particular with regards this question, just curious. Is
I was asked this question in an interview would appreciate your answers. Regards; Mohammad
I was looking at this question Here in regards to this library. However it
First of all, this question is in regards to PHP and MySQL I have

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.