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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:26:05+00:00 2026-05-28T16:26:05+00:00

Are there non-static equivalents to MSTest’s [ClassCleanup] & [ClassInitialize]? I am using MSTest for

  • 0

Are there non-static equivalents to MSTest’s [ClassCleanup] & [ClassInitialize]?

I am using MSTest for some system/integration level tests, and I don’t want to have to worry about cleaning & initializing the connection in the tests.

Example Code:

[TestClass]
public class DefectCreatorTest
{
    private long _cookie;
    private soapcgi _soap;

    [ClassInitialize]
    public void Initialize()
    {
        _soap = new soapcgi {Url = "http://localhost:80/scripts/soapcgi.exe"};
        _cookie = Transaction.Login(_soap);
    }

    [ClassCleanup]
    public void TearDown()
    {
        Transaction.Logout(_cookie, _soap);
    }

    [TestMethod]
    public void CreateDefectTest()
    {
        var result = _soap.Foo();
        Assert.AreEqual("bar", result);
    }
}
  • 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-28T16:26:07+00:00Added an answer on May 28, 2026 at 4:26 pm

    Answering your question, as far as i know – No, there isn’t a non-static equivalent in MSTest.

    But:

    1. looking at your code, there is no reason why _cookie and _soap shouldn’t be made static, along with Initialize and TearDown. Doing so will let you forget the configuration worries during test writing…
    2. If you are willing to “jump ship”, The NUnit equivalents for [ClassCleanup] & [ClassInitialize] can be applied to static & instance methods.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering whether there's any advantages to using a static member function when
Is there a way to implement wait(); (non-static method) in a static context. For
I'm using the Apache Commons EqualsBuilder to build the equals method for a non-static
Is there anything wrong in my code? using System; using System.Windows.Forms; public class MyProgram
In a book there is an example about static/non-static objects. char buf[MAX]; long count=0;
I have a non-static C# class with some instance methods, which I need to
Is there a non-IIS way of authenticating users that is not with HTML? I
Is there anything non-RESTful about providing parameters to a HTTP DELETE request? My scenario
Is there any non-hacky way to determine wether a class' superclass implements a particular
I know there are non-standard frameworks such as commons-validator, and hibernate validator. I wanted

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.