Timeline for Should one test the values of an enum using unit tests?
Current License: CC BY-SA 3.0
6 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Sep 28, 2017 at 19:56 | vote | accept | IS1_SO | ||
Sep 28, 2017 at 16:09 | comment | added | Baldrickk |
@IS1_SO lets say you have an enum of error codes, and you want to throw a null_ptr error. Now that has an error code via the enum. The code checking for a null_ptr error looks up the code via the enum too. So it may have a value of 5 (for ex). Now you need to add another error code. The enum is changed (lets say we add a new one to the top of the enum) The value of null_ptr is now 6 . Is this a problem? you now return an error code of 6 and test for 6 . As long as everything is logically consistent, you are fine, despite this change breaking your theoretical test.
|
|
Sep 27, 2017 at 20:05 | comment | added | anotherdave |
@IS1_SO — to VOU's point that one test should fail though: did it? In which case, you didn't need to test the Enum specifically. Did it not? Maybe that's a sign that you could model your code more simply and create an abstraction over the 'true nature' of the data — e.g. regardless of the cards in a deck, do you really need to have an representation of [Hearts , Spades , Diamonds ,Clubs ] if you only ever card if a card is red/black?
|
|
Sep 27, 2017 at 14:32 | history | edited | VoiceOfUnreason | CC BY-SA 3.0 |
deleted 104 characters in body
|
Sep 27, 2017 at 14:32 | comment | added | IS1_SO | But in this case the implementation detail coincides with the "true nature" of the data, that is: a set (in the mathematical sense) of values. You could arguably use an immutable set, but the same values should still be present there. If you use an array the same thing must be done to test the business logic. I think the conundrum here is the fact that the language construct coincides very well with the nature of the data. I am not sure if I've explained myself correctly. | |
Sep 27, 2017 at 14:27 | history | answered | VoiceOfUnreason | CC BY-SA 3.0 |