31 lines
712 B
Plaintext
31 lines
712 B
Plaintext
![]() |
== How to fix it in NUnit
|
||
|
|
||
|
Remove the `ExpectedException` attribute in favor of using the https://docs.nunit.org/articles/nunit/writing-tests/assertions/classic-assertions/Assert.Throws.html[Assert.Throws] assertion.
|
||
|
|
||
|
=== Code examples
|
||
|
|
||
|
==== Noncompliant code example
|
||
|
|
||
|
[source,csharp,diff-id=2,diff-type=noncompliant]
|
||
|
----
|
||
|
[Test]
|
||
|
[ExpectedException(typeof(ArgumentNullException))] // Noncompliant
|
||
|
public void Method_NullParam()
|
||
|
{
|
||
|
var sut = new MyService();
|
||
|
sut.Method(null);
|
||
|
}
|
||
|
----
|
||
|
|
||
|
==== Compliant solution
|
||
|
|
||
|
[source,csharp,diff-id=2,diff-type=compliant]
|
||
|
----
|
||
|
[Test]
|
||
|
public void Method_NullParam()
|
||
|
{
|
||
|
var sut = new MyService();
|
||
|
Assert.Throws<ArgumentNullException>(() => sut.Method(null));
|
||
|
}
|
||
|
----
|