Are multiple asserts bad in a unit test? Even if chaining?

后端 未结 6 1385
借酒劲吻你
借酒劲吻你 2020-12-24 01:23

Is there anything wrong with checking so many things in this unit test?:

ActualModel = ActualResult.AssertViewRendered()        // check 1
                           


        
6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-24 02:01

    As others have pointed out, it's best to stick with one assert in each test in order to avoid losing information - if the first assert fails, you don't know whether the later ones would fail also. You have to fix the problem with less information - which might (probably will) be harder.

    A very good reference is Roy Osherove's Art of Unit Testing - if you want to get started right with Unit Testing, you could do a lot worse than starting here.

提交回复
热议问题