如何转义双引号作为 NUnit TestCase 的参数?
我尝试为用 VB.net 编写的 NUnit 测试编写以下 TestCase:
<TestCase("FirstNode", "<node id=\"FirstNode\">")>
Public Sub GetNode_GivenSomeNodeId_ReturnCorrectNode(ByVal nodeId as String,
ByVal expectedXml as String)
(Call the method under test and request the xmlNode with the provided id...)
Assert.AreEqual(expectedXml, returnedXml)
End Sub
但是,作为第二个参数传递给测试用例的 xml 节点无效,因为这显然不是转义双引号的正确方法。我确信我可以找到一种解决方法来检查被测试的方法是否返回预期的 XML 节点,但我很好奇:
是否有一些聪明的方法来传递这样的包含双引号的字符串作为NUnit 测试的参数?
I tried writing the following TestCase for an NUnit test written in VB.net:
<TestCase("FirstNode", "<node id=\"FirstNode\">")>
Public Sub GetNode_GivenSomeNodeId_ReturnCorrectNode(ByVal nodeId as String,
ByVal expectedXml as String)
(Call the method under test and request the xmlNode with the provided id...)
Assert.AreEqual(expectedXml, returnedXml)
End Sub
The xml-node passed as the second parameter to the testcase is not valid however, as this clearly is not the correct way to escape double quotes. I'm sure I can find a workaround in order to check that the method under test returns the expected XML-node, but I'm curious:
Is there some clever way to pass a string such as this, containing double quotes, as a parameter to an NUnit test?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 VB 中转义双引号的正确方法是将双引号加倍:
The correct way to escape double-quotes in VB is by doubling the double-quotes: