Writing standards for unit testing

前端 未结 10 933
自闭症患者
自闭症患者 2021-01-31 12:05

I plan to introduce a set of standards for writing unit tests into my team. But what to include?

These two posts (Unit test naming best practices and Best practices for

10条回答
  •  说谎
    说谎 (楼主)
    2021-01-31 12:47

    Have a look at Michael Feathers on what is a unit test (or what makes unit tests bad unit tests)

    Have a look at the idea of "Arrange, Act, Assert", i.e. the idea that a test does only three things, in a fixed order:

    • Arrange any input data and processing classes needed for the test
    • Perform the action under test
    • Test the results with one or more asserts. Yes, it can be more than one assert, so long as they all work to test the action that was performed.

    Have a Look at Behaviour Driven Development for a way to align test cases with requirements.

    Also, my opinion of standard documents today is that you shouldn't write them unless you have to - there are lots of resources available already written. Link to them rather than rehashing their content. Provide a reading list for developers who want to know more.

提交回复
热议问题