2
我是使用mstest框架編寫單元測試用例的新手,我被困在從xml文件中檢索新行字符以作爲期望值的輸入。下面是一塊測試方法從xml文件中檢索時,不保留換行符。我已經使用cdata
public void ExtractNewLineTest()
{
MathLibraray target = new MathLibraray(); // TODO: Initialize to an appropriate value
string expected = TestContext.DataRow["ExpectedValue"].ToString(); => I am retrieving the value from the xml file.
string actual;
actual = target.ExtractNewLine();
Assert.AreEqual(expected, actual);
}
下面的是XML內容
<ExtractNewLineTest>
<ExpectedValue><![CDATA[select distinct\tCDBREGNO,\r\n\tMOLWEIGHT,\r\n\tMDLNUMBER\r\nfrom Mol]]></ExpectedValue>
</ExtractNewLineTest>
當我取回從XML預期值的數據,我得到以下字符串
ExpectedValue = 「select distinct\\tCDBREGNO,\\r\\n\\tMOLWEIGHT,\\r\\n\\tMDLNUMBER\\r\\nfrom Mol」;
如果我們看到上面的值,\ n和\ r會添加額外的斜槓。 請讓我知道,我該如何聲明這個價值。謝謝!
你能幫我在這種情況下如何斷言。那挺棒的! – vasujc
@vasujc:一旦你獲得了*正確的*期望值,你就可以像正常一樣斷言。 –
非常感謝您的投入!它確實幫助我解決了我的問題。我也會跟蹤 – vasujc