To test that something throws for example an ArgumentException
I can do this:
Assert.Throws<ArgumentException>(() => dog.BarkAt(deafDog));
How can I check that the ParamName
is correct in a clear way? And bonus question: Or would you perhaps perhaps recommend not testing this at all?
What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.
The main difference between C and C++ is that C is a procedural programming language that does not support classes and objects. On the other hand, C++ is an extension of C programming with object-oriented programming (OOP) support.
In C programming language, %d and %i are format specifiers as where %d specifies the type of variable as decimal and %i specifies the type as integer. In usage terms, there is no difference in printf() function output while printing a number using %d or %i but using scanf the difference occurs.
Found a pretty clear way (but please let me know if anyone have an even better one!)
var e = Assert.Throws<ArgumentException>(() => dog.BarkAt(deafDog));
Assert.That(e.ParamName, Is.EqualTo("otherDog"));
Facepalm...
If you want to do more with the exception than just assert that it is thrown, then Assert.Throws
actually returns the exception and you can do this:
var exception = Assert.Throws<ArgumentException>(() => dog.BarkAt(deafDog));
// Assert something else about the exception
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With