atr*_*eon 4 unit-testing mstest
我需要比较两个文本块的差异,以确定我的单元测试是否已通过.不幸的是,文本长度大约为500个字符,如果只有一个字符不同,则很难发现问题所在.MSTest并没有告诉我哪些个性字符不同,它只是告诉我存在差异.
单元测试时比较这样的文本的最佳方法是什么?
(我正在使用MSTest(我会考虑转移到NUnit,但我不愿意,因为我的所有测试都已经在MSTest中编写)
有一个专门为这种情况设计的图书馆批准测试.它支持mstest和nunit.
库是围绕"Golden Copy"测试方法构建的 - 一个主数据集的可信副本,您将准备和验证一次
[TestClass]
public Tests
{
[TestMethod]
public void LongTextTest()
{
// act: get long-long text
string longText = GetLongText();
//assert: will compare longText variable with file
// Tests.LongTextTest.approved.txt
// if there is some differences,
// it will start default diff tool to show actual differences
Approvals.Verify(longText);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1521 次 |
| 最近记录: |