如何将双引号作为参数转义为NUnit TestCase? [英] How to escape double quotes in as a parameter to an NUnit TestCase?
问题描述
我尝试编写以下TestCase,用VB.net编写的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
作为第二个参数传递给测试用例的xml-node是无效的,因为这显然不是正确的方式来排除双引号。我确定我可以找到一个解决方法,以检查测试中的方法是否返回预期的XML节点,但我很好奇:
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:
有没有一些聪明传递一个诸如此类的字符串的方式,包含双引号,作为NUnit测试的参数?
Is there some clever way to pass a string such as this, containing double quotes, as a parameter to an NUnit test?
推荐答案
正确的方法VB中的转义双引号是双引号的倍增:
The correct way to escape double-quotes in VB is by doubling the double-quotes:
<TestCase("FirstNode", "<node id=""FirstNode"">")>
这篇关于如何将双引号作为参数转义为NUnit TestCase?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!