Inherited test class from generic base is ignored in MSTest

后端 未结 4 706
死守一世寂寞
死守一世寂寞 2021-01-04 00:14

When creating a generic base test class in MSTest, and inheriting from it, I\'m unable to run the tests of all the inheriting classes.

4条回答
  •  Happy的楠姐
    2021-01-04 00:52

    Nothing special, but another way of solving the problem by calling base methods is:

    public abstract class AccountBaseTest
    {
        protected abstract IAccountRepository GetAccountRepository();
    
        public void _submitAccountToLMS_BlankAccount_NewLmsID()
        {
           Account account = new Account(GetAccountRepository());
           account.FirstName = Faker.FirstName();
           account.LastName = Faker.LastName();
           account.SubmitToLms();
           Assert.IsTrue(account.LmsID > 0);
        }
    }
    
    
    
    [TestClass]
    public class AccountIntegrationTest
    {
        protected override IAccountRepository GetAccountRepository()
        {
            return new AccountRepository();
        }
    
        [TestMethod]
        public void SubmitAccountToLMS_BlankAccount_NewLmsID()
        {
           base._submitAccountToLMS_BlankAccount_NewLmsID();
        }
    }
    

    Hopefully VS 2012 will fix this problem....

提交回复
热议问题