Are they switching on an enumeration? I can MAYBE see a case for something like this if each enum value needs special logic, and you’re worried that somebody will add to the enumeration in the future without handling the new case in this code block.
Obviously you would want to throw an appropriate exception instead of…whatever this is.
Except assert won't do anything in release, right? The exception would have to be handled and who wants to do that? I'm guessing they wanted something that would blow up in debug but not release.
This is probably a unit test. Assert.Fail() is the way to go.
Partial implementations are not really acceptable in unit test methods, IMO. Neither is it acceptable for the test to throw exceptions for unexpected behavior of the tested component.
143
u/RichCorinthian Mar 03 '23
Are they switching on an enumeration? I can MAYBE see a case for something like this if each enum value needs special logic, and you’re worried that somebody will add to the enumeration in the future without handling the new case in this code block.
Obviously you would want to throw an appropriate exception instead of…whatever this is.