29 lines
766 B
Plaintext
29 lines
766 B
Plaintext
== How to fix it in MSTest
|
|
|
|
Remove the `ExpectedException` attribute in favor of using the https://learn.microsoft.com/en-us/dotnet/api/microsoft.visualstudio.testtools.unittesting.assert.throwsexception[Assert.ThrowsException] assertion.
|
|
|
|
=== Code examples
|
|
|
|
==== Noncompliant code example
|
|
|
|
[source,vbnet,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
<TestMethod>
|
|
<ExpectedException(GetType(ArgumentNullException))> ' Noncompliant
|
|
Public Sub Method_NullParam()
|
|
Dim sut As New MyService()
|
|
sut.Method(Nothing)
|
|
End Sub
|
|
----
|
|
|
|
==== Compliant solution
|
|
|
|
[source,vbnet,diff-id=1,diff-type=compliant]
|
|
----
|
|
<TestMethod>
|
|
Public Sub Method_NullParam()
|
|
Dim sut As New MyService()
|
|
Assert.ThrowsException(Of ArgumentNullException)(Sub() sut.Method(Nothing))
|
|
End Sub
|
|
----
|