Should I use AutoMapper in my unit tests?

前端 未结 2 1632
滥情空心
滥情空心 2021-02-20 11:30

I\'m writing unit tests for ASP.NET MVC controller methods.

Those controllers have a dependency on IMapper - an interface I\'ve created to abstract AutoMapp

2条回答
  •  北恋
    北恋 (楼主)
    2021-02-20 11:52

    I could tend to agree with #2. You know automapper works, you know your injection works ( got tests for that right? :-) ) I would focus more on specifics, things that aren't just SomeClass.Property = AnotherClass.Property -- THOSE special cases should be tested not basic copy functions. Don't test framework stuff.

    As for more test code - I feel that's completely ok. Tests should be setup within the given tests (also within reason) for just that given unit.

    Regarding Moq, syntax is easy, don't overthink it. var obj = new Mock(); then set your properties like obj.Setup(x => x.Property).returns("hello") unless you have a more specific issue? Moq also has setup all properties on it as well, so you may not even need automapper

    -edit- found it, it's obj.SetupAllProperties();

提交回复
热议问题