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
Post a Comment