rspec/rules/S3431/vbnet/how-nunit.adoc
2024-08-09 10:58:55 +02:00

29 lines
723 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,vbnet,diff-id=2,diff-type=noncompliant]
----
<Test>
<ExpectedException(GetType(ArgumentNullException))> ' Noncompliant
Public Sub Method_NullParam()
Dim sut As New MyService()
sut.Method(Nothing)
End Sub
----
==== Compliant solution
[source,vbnet,diff-id=2,diff-type=compliant]
----
<Test>
Public Sub Method_NullParam()
Dim sut As New MyService()
Assert.Throws(Of ArgumentNullException)(Sub() sut.Method(Nothing))
End Sub
----