我有classX:怪異NUnit的單元測試失敗
的Sub New(BYVAL item_line_no作爲字符串,BYVAL ITEM_TEXT作爲字符串)
' check to ensure that the parameters do not exceed the file template limits
Select Case item_line_no.Length
Case Is > m_item_line_no_capacity
Throw New ArgumentOutOfRangeException(item_line_no, "Line No exceeds 4 characters")
Case Else
Me.m_item_line_no = item_line_no
End Select
Select Case item_text.Length
Case Is > m_item_free_text_capacity
Throw New ArgumentOutOfRangeException("Free Text Exceeds 130 characters")
Case Else
Me.m_item_free_text = item_text
End Select
End Sub
和以下unti來測試一個故障點
<ExpectedException(GetType(ArgumentOutOfRangeException), "Line No exceeds 4 characters")> _
<Test()> _
Sub testLineNoExceedsMaxLength()
Dim it As New X("aaaaa", "Test")
End Sub
當我運行測試時,我期望得到異常中的消息「Line No than 4 characters」
然而單元測試失敗,出現以下消息
RecordTests.testLineNoExceedsMaxLength : FailedExpected exception message: Line No exceeds 4 characters
got: Line No exceeds 4 characters
Parameter name: aaaaa
我想簡單的東西,但它讓我瘋狂。
注:在的ExpectedException的聲明,我得到一個過時的警告,指出代替
<ExpectedException(GetType(ArgumentOutOfRangeException), "Line No exceeds 4 characters")>
應該
<ExpectedException(GetType(ArgumentOutOfRangeException), ExpectedException="Line No exceeds 4 characters")>
然而,這將引發的ExpectedException未聲明的錯誤!