Should it be “Arrange-Assert-Act-Assert”?

后端 未结 14 2514
不思量自难忘°
不思量自难忘° 2020-11-30 19:53

Regarding the classic test pattern of Arrange-Act-Assert, I frequently find myself adding a counter-assertion that precedes Act. This way I know that the passing assertion

14条回答
  •  一整个雨季
    2020-11-30 20:47

    Have a look at Wikipedia's entry on Design by Contract. The Arrange-Act-Assert holy trinity is an attempt to encode some of the same concepts and is about proving program correctness. From the article:

    The notion of a contract extends down to the method/procedure level; the
    contract for each method will normally contain the following pieces of
    information:
    
        Acceptable and unacceptable input values or types, and their meanings
        Return values or types, and their meanings
        Error and exception condition values or types that can occur, and their meanings
        Side effects
        Preconditions
        Postconditions
        Invariants
        (more rarely) Performance guarantees, e.g. for time or space used
    

    There is a tradeoff between the amount of effort spent on setting this up and the value it adds. A-A-A is a useful reminder for the minimum steps required but shouldn't discourage anyone from creating additional steps.

提交回复
热议问题