How to escape double quotes in as a parameter to an NUnit TestCase?

对着背影说爱祢 提交于 2019-11-27 03:02:19

问题


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?


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!