MsTest ClassInitialize and Inheritance

后端 未结 4 1146
小鲜肉
小鲜肉 2020-12-05 12:17

I have a base class for my tests which is composed in the following way:

[TestClass]
public abstract class MyBaseTest
{
   protected static string myField =          


        
4条回答
  •  误落风尘
    2020-12-05 12:59

    A potential workaround is to define a new class with AssemblyInitializeAttribute instead. It has a different scope, obviously, but for me it meets my needs (cross-cutting concerns, which just so happen to require exactly the same settings for every test class and test method.)

    using Microsoft.VisualStudio.TestTools.UnitTesting;
    
    namespace MyTests
    {
      [TestClass]
      public sealed class TestAssemblyInitialize
      {
        [AssemblyInitialize]
        public static void Initialize(TestContext context)
        {
          ...
        }
      }
    }
    

提交回复
热议问题