How many unit tests should I write per function/method?

后端 未结 12 2098
忘了有多久
忘了有多久 2020-12-05 18:36

Do you write one test per function/method, with multiple checks in the test, or a test for each check?

12条回答
  •  温柔的废话
    2020-12-05 18:47

    One test per check and super descriptive names, per instance:

    @Test
    public void userCannotVoteDownWhenScoreIsLessThanOneHundred() {
     ...
    }
    

    Both only one assertion and using good names gives me a better report when a test fails. They scream to me: "You broke THAT rule!".

提交回复
热议问题