Best way to test exceptions with Assert to ensure they will be thrown

前端 未结 9 1747
悲哀的现实
悲哀的现实 2020-12-02 06:58

Do you think that this is a good way for testing exceptions? Any suggestions?

Exception exception = null;
try{
    //I m sure that an exeption will happen he         


        
9条回答
  •  北海茫月
    2020-12-02 07:43

    Mark the test with the ExpectedExceptionAttribute (this is the term in NUnit or MSTest; users of other unit testing frameworks may need to translate).

提交回复
热议问题