Geeks With Blogs
Abhishek Anand Bits & Bytes about .net technology framework.

AssemblyInitialize is very similar to the ClassInitialize and TestInitialize attributes, but rather than executing before classes/methods are run it executes before the any method marked with TestMethod, ClassInitialize, or TestInitialize inside this assembly. Only one method in an assembly can be annotated with this attribute.

 

Code that belongs in the method decorated with AssemblyInitialize is any code that sets up shared resources that are used by tests across the assembly. Tests should not change any of the resources setup by this method, since it can cause unexpected behavior inside of other tests in the assembly. If a resource needs be changed in a test, and other tests rely on its information it is probably a candidate for TestInitialize or ClassInitialize decorated methods.

 

    [TestClass()]

    public sealed class TestClass1

    {

        [AssemblyInitialize()]

        public static void AssemblyInit(TestContext context)

        {

            Console.WriteLine("AssemblyInit " + context.TestName);

        }

 

        [ClassInitialize()]

        public static void ClassInit(TestContext context)

        {

            Console.WriteLine("ClassInit " + context.TestName);

        }

 

        [TestInitialize()]

        public void Initialize()

        {

            Console.WriteLine("TestMethodInit");

        }

        [TestMethod()]

        public void MethodTest1()

        {

            Console.WriteLine("Executing Test...");

        }

 

    }

Posted on Monday, November 18, 2013 7:13 PM .net , unit testing | Back to top


Comments on this post: Assembly Initialize

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Abhishek Anand | Powered by: GeeksWithBlogs.net