vb.net 如何将双引号转义为 NUnit TestCase 的参数?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7726420/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to escape double quotes in as a parameter to an NUnit TestCase?
提问by Kjartan
I tried writing the following TestCase for an NUnit test written in VB.net:
我尝试为用 VB.net 编写的 NUnit 测试编写以下测试用例:
<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:
然而,作为第二个参数传递给测试用例的 xml-node 是无效的,因为这显然不是转义双引号的正确方法。我确定我可以找到一种解决方法来检查被测方法是否返回预期的 XML 节点,但我很好奇:
Is there some clever way to pass a string such as this, containing double quotes, as a parameter to an NUnit test?
是否有一些巧妙的方法可以将包含双引号的字符串作为参数传递给 NUnit 测试?
回答by Meta-Knight
The correct way to escape double-quotes in VB is by doubling the double-quotes:
在 VB 中转义双引号的正确方法是将双引号加倍:
<TestCase("FirstNode", "<node id=""FirstNode"">")>