Check several different example inputs in a single test?

前端 未结 7 864
感情败类
感情败类 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条回答
  •  终归单人心
    2021-01-17 08:07

    I don't think that you should write separate test for each case since all the cases are related to the same thing which is testing that the string is the correct email address. If you are using MbUnit or NUnit for running your tests then you can use the RowTest and Row attribute to pass in different values to the test. Another way is to store all the different email formats in an array and loop over the array and perform the assert.

提交回复
热议问题