新しい NUnit バージョン 3.x はサポートされExpectedExceptionAttribute
なくなりました。代わりがありAssert.Throws<MyException>()
ます。おそらくより良い論理的概念です。しかし、私は古い良品に代わるものを見つけることができませんでしたMatchType
- ありますか? MyException
NUnit 2.x では、特定のテキスト フラグメントが含まれていることを示す例外メッセージを比較して、どのパラメーターが使用されたかを知ることができました (もちろん、代わりに多数の例外クラスを用意するつもりはありません)。論理的なものの)。これを NUnit 3.x でどのように処理できますか? ヒントを見つけることができませんでした。
NUnit 2.x では、次のようにします。
[Test]
[ExpectedException(ExpectedException=typeof(MyException), ExpectedMessage="NON_EXISTENT_KEY", MatchType=MessageMatch.Contains)]
public void DeletePatient_PatientExists_Succeeds()
{
Person p = new Person("P12345", "Testmann^Theo", new DateTime(1960, 11, 5), Gender.Male);
MyDatabase.Insert(p);
MyDatabase.Delete(p.Key);
// Attemp to select from a database with a non-existent key.
// MyDatabase throws an exception of type MyException with "NON_EXISTENT_KEY" within the message string,
// so that I can distinguish it from cases where MyException is thrown with different message strings.
Person p1 = MyDatabase.Select(p.Key);
}
NUnt 3.x で同様のことを行うにはどうすればよいですか?
私の言いたいことを考えてください: NUnit が提供する手段は、例外がスローされたパラメーターを認識するのに十分ではないため、これは別の質問です。