c# - NUnit Theory with an exception -


it design/pattern looking for.

i have nunit test, in plan use existing enum theory. existing enum has 30 members.

say it's like:

enum abigenum {     a,     b,     c,     d }   [theory] public void test(abigenum enumvalue) { //generate somevalue based upon enumvalue     assert.that(somevalue, is.true, "an amazing assertion message"); } 

but, test should assert, value d in enum false , others true. can without using if-else conditional (as holy doctrine avoid conditionals in tests)? or there interesting pattern guys follow?

you should able achieve requirements this:

enum abigenum {     a,     b,     c,     d }  [theory] public void test(abigenum enumvalue) {     bool somevalue = enumvalue != abigenum.d;     assert.that(somevalue, is.true, "an amazing assertion message"); } 

this give false when passing in d , true other values.

because logic not can "known" system have make kind of decision whether if / else or switch.

however, "test" looks more method pure test , might want re-think testing , trying achieve because highlight don't want lot of logic in test.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -