我正在从两个文件中读取内容,现在我想用预期的字符串测试该内容。
string read1 = File.ReadAllText("@C:\somefile.txt");
string read2 = File.ReadAllText("@C:\somefilee.txt");
string expectedString = "blah";
Assert.AreEqual(read1 and read2 equals expected );
我知道这很基本,但是我有点卡在这里。
最佳答案
您需要使用2个断言,首先将期望的字符串与第一个文件内容进行比较,然后将第二个文件的内容与第一个文件内容进行比较(或再次与期望的字符串进行比较),例如:
Assert.AreEqual(expectedString, read1, "File content should be equal to expected string");
Assert.AreEqual(read1, read2, "Files content should be identical");
或者你可以使用条件
Assert.IsTrue(read1 == read2 == expectedString, "Files content should be equal to expected string");
但是在这种情况下,如果测试失败,您将不知道问题出在哪里。
关于c# - 断言很基本,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15357560/