[英]How to get properly formatted test results with nunit constraints
My custom constraint collects messages about expected values and actual values. 我的自定义约束收集有关期望值和实际值的消息。 They are written to the 'MessageWriter' by overriding 'WriteDescriptionTo': 通过覆盖“ WriteDescriptionTo”将它们写入“ MessageWriter”:
public override void WriteDescriptionTo(MessageWriter writer)
{
writer.WriteExpectedValue(_expectedMessages);
writer.WriteActualValue(_actualMessages);
}
But in the test results all information is in the expected result: 但是在测试结果中,所有信息都在预期结果中:
Expected: < On item 2 expected: Expected Reversible: True <> On item 2 actual: Actual Reversible: False > But was: <UNSET> 预期:<关于项目2预期:预期可逆:真<>关于项目2实际:实际可逆:假>但为:<UNSET>
NOTE: I fail in formatting the text here, it refuses to use respect my newlines. 注意:我无法在此处格式化文本,它拒绝尊重我的换行符。 So here's a screenshot of the result text: 因此,这是结果文本的屏幕截图:
The "But was:" part remains <UNSET> “但是是:”部分仍为<UNSET>
So how to get the actual text to the right spot? 那么如何使实际文本正确呢?
It's not a huge problem, just really annoying that I seem to be using the right method but it won't work, even seems like a bug in nunit. 这不是一个大问题,只是让我似乎在使用正确的方法感到非常恼火,但它却无法正常工作,甚至似乎是nunit中的一个错误。
Okay, I checked the source of NUnit. 好的,我检查了NUnit的来源。 The actual line is always generated by the framework, whether or not you called WriteActualValue
before. 实际的行始终由框架生成,无论您之前是否调用过WriteActualValue
。
Instead you should set the actual
field of your custom constraint (inherited from Constraint
) to your _actualMessages
stuff (or you refactor your code to live without _actualMessages
at all). 相反,您应该将自定义约束的actual
字段(从Constraint
继承)设置为_actualMessages
内容(或者重构代码以完全不使用_actualMessages
生存)。 This should bring your expected output. 这应该会带来预期的输出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.