c# - I want to assert that an exception was thrown within a certain class -


i building testproject client/server setup. want verify test fails within block of execution (there no client send server's send() method throw exception). since not want have tests boot client , server , have them communicate (which have had problems doing on single machine.)

if code reaches line, means program's execution flow fail within responsibilities of test. there easier way other doing substring check on thrown exception's stacktrace? feel method not expandable , require constant attention if class names change.

is there way doesn't involve manually checking exception's stacktrace?

if using nunit

without using dataannotations

[test] public void test_xxxxxxx {     var yourclass = new yourclass();      assert.that(()=>yourclass.method(),                     .throws.exception                     .typeof<typeofyourexception>                     .with.property("message")                     .equalto("the message expecting goes here")                ); } 

using dataannotations

[test] [expectedexception(typeof(exceptiontype), expectedmessage="your message goes here!")] public void test_xxxxxxx {       var yourclass = new yourclass();            // call method in way fail       yourclass.yourmethod(); } 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -