奇怪的 nUnit 单元测试失败

编程入门 行业动态 更新时间:2024-10-11 07:29:51
本文介绍了奇怪的 nUnit 单元测试失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有 classX:

Sub New(ByVal item_line_no As String, ByVal item_text As String)

Sub New(ByVal item_line_no As String, ByVal item_text As String)

' 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

以及以下直到测试一个故障点

and the following unti to test one point of failure

<ExpectedException(GetType(ArgumentOutOfRangeException), "Line No exceeds 4 characters")> _ <Test()> _ Sub testLineNoExceedsMaxLength() Dim it As New X("aaaaa", "Test") End Sub

当我运行测试时,我希望得到在异常行号超过 4 个字符"中抛出的消息

When I run the test I expect to get the message thrown in the exception "Line No exceeds 4 characters"

但是单元测试失败并显示以下消息

However the unit test fails with the following message

RecordTests.testLineNoExceedsMaxLength : FailedExpected exception message: Line No exceeds 4 characters got: Line No exceeds 4 characters Parameter name: aaaaa

我认为这很简单,但它让我发疯.

I think the something simple but it driving me insane.

注意:在 ExpectedException 的声明中,我收到了一个过时的警告,说明不是

NOTE: in the declaration of the ExpectedException I get an obsolete warning stating that instead of

<ExpectedException(GetType(ArgumentOutOfRangeException), "Line No exceeds 4 characters")>

应该是

<ExpectedException(GetType(ArgumentOutOfRangeException), ExpectedException="Line No exceeds 4 characters")>

然而这会抛出一个未声明错误的预期异常!

However this throws a ExpectedException is not declared error!

推荐答案

好的.只需运行这个.

异常的消息是:

行号超过 4 个字符

参数名称:aaaaa

(包括换行符)

您需要将所有这些都指定为预期消息:

You need to specify this all of this as the expected message:

<ExpectedException(GetType(ArgumentOutOfRangeException), ExpectedMessage="Line No exceeds 4 characters" & VbCrLf & "Parameter name: aaaaa")>

更多推荐

奇怪的 nUnit 单元测试失败

本文发布于:2023-10-10 21:55:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1479865.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单元测试   奇怪   nUnit

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!