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

后端 未结 14 2560
不思量自难忘°
不思量自难忘° 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:44

    I have done this before when investigating a test that failed.

    After considerable head scratching, I determined that the cause was the methods called during "Arrange" were not working correctly. The test failure was misleading. I added a Assert after the arrange. This made the test fail in a place which highlighted the actual problem.

    I think there is also a code smell here if the Arrange part of the test is too long and complicated.

提交回复
热议问题