linq - Is there a C# unit test framework that supports arbitrary expressions rather than a limited set of adhoc methods? -


basically nunit, xunit, mbunit, mstest , have methods similar following:

assert.isgreater(a,b) //or, little more discoverable assert.that(a, is.greaterthan(b)) 

however, there limited number of such comparison operators built-in; , duplicate languages operators needlessly. when want complex, such as...

assert.that(a.sequenceequals(b)) 

i'm either left digging through manual find equivalent of expression in nunit-speak, or forced fall-back plain boolean assertions less helpful error messages.

c#, however, integrates arbitrary expressions - should possible have method following signature:

void that(expression<func<bool>> expr); 

such method used both execute test (i.e. validate assertion) , provide less-opaque diagnostics in case of test failure; after all, expression can rendered pseudo-code indicate expression failed; , effort, evaluate failing expressions intelligently give clue of value of subexpressions.

for example:

assert.that(()=> == b);//could inspect expression , print , b assert.that(()=> < b && b < c); //could mention values of "a<b" , "b<c" and/or list values of a, b, , c. 

at minimum, make use of parallel language expressions unnecessary, , in cases might make failure messages more useful.

does such thing exist?

edit: after trying (and liking!) power assert, ended reimplementing address several limitations. variant of published expressiontocode; see my answer below list of improvements.

check out powerassert library (example output below):

passert.istrue(() => x + 5 == d.month * y);   system.exception : istrue failed, expression was:  x + 5 == d.month * y | |   |  | |     | | | |   |  | |     | 6 | |   |  | |     18 | |   |  | 3 | |   |  01/03/2010 00:00:00 | |   false | 16 11 

http://powerassert.codeplex.com/


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -