xunit assert.equal 错误?
我刚刚开始使用大量现有代码开发一个新项目,但测试未通过。我更喜欢 Nunit,所以我不太熟悉 Xunit 的故障点。
问题出在类似这样的代码中:
fooStringProperty = readSomeFile;
//later
fooStringProperty.ShouldBe(expectedContents)
上面的代码失败并出现类似这样的错误:
error : Position: First difference is at position 0
Expected: contentsOfFooStringProperty
Actual:
contentsOfFooStringProperty
基本上,它以某种方式将换行符放在那里,我不知道如何。我的代码库中存在大量此类失败,并且它对其他人也适用,所以我想知道这是否是某些 xunit 版本问题?
编辑:这完全是 mac 和 windows 之间的 CRLF 问题。问题已解决:)
I just started working on a new project with a ton of existing code, and the tests are not passing. I'm more of an Nunit guy, so I'm not immediately familiar with the failure points of Xunit.
the problem is in code that sort of looks like this:
fooStringProperty = readSomeFile;
//later
fooStringProperty.ShouldBe(expectedContents)
the above code fails with an error that looks like this:
error : Position: First difference is at position 0
Expected: contentsOfFooStringProperty
Actual:
contentsOfFooStringProperty
basically, it's somehow getting this newline in there, and I have no idea how. I have a ton of these failures all over the code base, and it works for other people, so I'm wondering if it's some xunit version issue?
edit: this is totally a CRLF issue between mac and windows. problem resolved :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
xUnit 似乎不太可能注入换行符。看起来更有可能的是,由于某些完全其他的原因,您确实拥有流氓换行符。
我建议您通过调试代码并检查调试器中的值来诊断此问题。在断言行上设置一个断点,看看它是否适合您。假设此时确实已损坏,请在获取/读取/计算每个值的位置放置一个断点。基本上应用正常步骤来解决意外行为 - 忽略 xUnit 方面。
It seems unlikely that xUnit is injecting newlines. It seems more likely that you really have got rogue newlines, for some completely other reason.
I would suggest that you diagnose this by debugging through the code and checking the values in the debugger. Set a breakpoint on the assertion line, and see whether it looks right to you. Assuming it really is broken at that point, put a breakpoint where you're fetching/reading/computing each value. Basically apply the normal steps to working out unexpected behaviour - ignore the xUnit aspect.