로딩
요청 처리 중입니다...

Assert.Throws를 사용하여 예외 유형을 어설션하려면 어떻게 합니까?

 Assert.Throws를 사용하여 예외 유형을 어설션하려면 어떻게 합니까?

Assert.Throws 를 사용하여 예외 유형과 실제 메시지 문구를 어설션하려면 어떻게 해야 합니까? 이 같은: Assert.Throws( ()=>user.MakeUserActive()).WithMessage("Actual exception message") 내가 테스트하는 방법은 다른 메시지와 함께 동일한 유형의 여러 메시지를 throw하며 컨텍스트에 따라 올바른 메시지가 throw되는지 테스트하는 방법이 필요합니다.

Assert.Throws 는 throw된 예외를 반환하여 예외에 대해 주장할 수 있습니다. var ex = Assert.Throws(() => user.MakeUserActive()); Assert.That(ex.Message, Is.EqualTo("Actual exception message")); 따라서 예외가 발생하지 않거나 잘못된 유형의 예외가 발생하면 첫 번째 Assert.Throws 어설션이 실패합니다. 그러나 올바...

# assertion # c # exception # nunit