In the teardown event during an NUnit test how can I get to the attribute applied to the method that was just tested?

前端 未结 4 379
心在旅途
心在旅途 2021-01-20 06:18

I have a test method that is run. When the method generates an exception I want to know what the name of the test was and the exception content.

In the teardown for

4条回答
  •  长发绾君心
    2021-01-20 07:02

    OPTION 1: I don't think you can. Or rather, I don't know that you can. How I approach this need is to use a try/catch on the specific tests, do what I want with the exception and then throw again within the catch block so that the test could fail.

    try{
        // do something that can potentially throw;
    }
    catch(Exception ex){
        // do something interesting with the ex;
        throw;
    }
    

    OPTION 2: If you've not gone too far along, you may want to use xUnit which has a different exception expectation model and may provide some of the control you are looking for.

提交回复
热议问题