Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practices in unit-test writing

I have a "best practices" question. I'm writing a test for a certain method, but there are multiple entry values. Should I write one test for each entry value or should I change the entryValues variable value, and call the .assert() method (doing it for all range of possible values)?

Thank you for your help. Best regards,

Pedro Magueija

edited: I'm using .NET. Visual Studio 2010 with VB.

like image 308
Pedro Magueija Avatar asked Dec 06 '25 08:12

Pedro Magueija


2 Answers

If one is having to write many tests which vary only in initial input and final output one should use a data driven test. This allows you to define the test once along with a mapping between input and output. The unit testing framework will then interpret it as being one test per case. How to actually do this depends on which framework you are using.

like image 174
Winston Ewert Avatar answered Dec 08 '25 00:12

Winston Ewert


It's better to have separate unit tests for each input/output sets covering the full spectrum of possible values for the method you are trying to test (or at least for those input/output sets that you want to unit test).

like image 43
Darin Dimitrov Avatar answered Dec 08 '25 00:12

Darin Dimitrov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!