Mocking vs. Test DB?

前端 未结 8 2079
无人及你
无人及你 2020-12-29 20:44

Earlier I asked this question How to correctly unit test my DAL?, one thing left unanswered for me is if to really test my DAL is to have a Test DB, then what is the role of

8条回答
  •  独厮守ぢ
    2020-12-29 21:41

    The problem could very well be in the original question. Some of the more popular examples of MVC use a shortcut by returning a DbSet such as:

    public class MusicStoreEntities : DbContext
        {
            public DbSet Albums { get; set; }
            public DbSet Genres { get; set; }
            public DbSet Artists { get; set; }
            public DbSet Carts { get; set; }
            public DbSet Orders { get; set; }
            public DbSet OrderDetails { get; set; }
        }
    

    To me this tightly couples the implementation of persistence which I believe is a bad thing. It woud be better to return List which could easily be mocked.

提交回复
热议问题