Check several different example inputs in a single test?

前端 未结 7 859
感情败类
感情败类 2021-01-17 07:31

Let\'s say I want to write a function that validates an email address with a regex. I write a little test to check my function and write the actual function. Make it pass.

7条回答
  •  -上瘾入骨i
    2021-01-17 08:10

    If the different incantations really boil down to the same thing it isn't a problem.

    However, if one of the email addresses suddenly breaks the test, you are going to have to debug to find out which case went wrong. So that seems a good reason to break them up.

    You would end up with millions of unit tests, which is right as they are after all tesing a unit of your application, but in practice multiple asserts will do providing that the way in which a failed assert breaks the test doesn't mess up the meaning of the failure.

提交回复
热议问题