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?
The correct way to escape double-quotes in VB is by doubling the double-quotes:
<TestCase("FirstNode", "<node id=""FirstNode"">")>
来源:https://stackoverflow.com/questions/7726420/how-to-escape-double-quotes-in-as-a-parameter-to-an-nunit-testcase