Thursday 15 July 2010

c# - How to unit test the default case of an enum based switch statement -


I have a switch statement in a factory that gives a command based on the value of the ambile. Something like this:

  Create public ICommand (EnumType enumType) {switch (enumType) {case (enumType.Val1): New SomeCommand (); Case (Anom Type Val 2): ​​Return to a New Commands (); Case (enumType.Val3): back some SomeCommand (); Default: Delete new argumentOffer exception ("unknown anonymous type" + ass type); }}  

I currently have a switch case for each value in enum. For each of these cases, I have unit tests. How can I test the unit that in the default case any error occurs? Obviously, at the moment I can not go into an unknown type of anum type, but who says that it will not change in the future. Can I expand or duplicate EnumType purely for unit testing anyway?

Try the following (

It is true that any value you choose for the "default" case may be a valid value one day. Just add a test that it is not in the same place, you check the default.


No comments:

Post a Comment