2011-08-03 6 views
1

アサーションが失敗したときにメッセージを提供したいが、それを行う方法がわからない。ExpectedException属性のエラーメッセージを表示する方法はありますか?

[Test] 
public void CreateInstanceTest() 
{ 
    SomeClass someClass = new SomeClass(); 
    Assert.IsNotNull(someClass, "Constructor could not return an instance"); 
    //provide failure message here 
} 

このテストではどうすればよいですか?

[Test] 
[ExpectedException(typeof(ArgumentNullException))] 
public void EmptyNameInConstructorThrowsExceptionTest() 
{ 
    SomeClass someClass = new SomeClass(null); 
} 

答えて

2
[Test] 
[ExpectedException(typeof(ArgumentNullException))] 
public void EmptyNameInConstructorThrowsExceptionTest() 
{ 
    SomeClass someClass = new SomeClass(null); 
    Assert.Fail("Exception not thrown"); 
} 
関連する問題