Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

MSTest Unit Test, what is ClassInitialize good for? What would I put in it?

$
0
0

I understand the order of execution concerning classinitialize and testinitialize etc... The problem I am having is what is it that I would use ClassInitialize for.  I've been beginning to write unit tests and thought that using ClassInitialize to instantiate a class object for the other test methods to reference would be nice within a class initiate.  However, the test methods cannot find the instance of the object that was created within the classintialize or testinitialize.  So...

What would you ever use ClassInitialize for? I'm looking for specific things. (I already know it is used to initialize things once before the test methods are ran, but what "things" should I be putting between the brackets? There are not very many examples out there) and...

How can I instantiate an object once before all other tests are ran? This is what I'm doing?

  [TestClass]
    public class UnitTest1:TestBase
    {
        ViewModel testView = new ViewModel();
        [TestMethod]
        public void NullValueShouldNotBeAddedToCollection()
        {
            // arrange


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>