简体   繁体   English

Nunit中的assert消息中使用什么字符串格式传递args

[英]What string format is used to pass args in assert message in Nunit

How can I create a string in Nunit and pass parameters to the error message如何在 Nunit 中创建字符串并将参数传递给错误消息

All (or almost all) Nunit asserts have a version that allows giving an error message with parameters.所有(或几乎所有)Nunit 断言都有一个版本,允许给出带有参数的错误消息。

For instance : 例如

Assert.Null(object anObject);
Assert.Null(object anObject, string message, params object[] params);

What format do I need to use the message in, in order to use the params?为了使用参数,我需要使用什么格式的消息?

I've searched the documentation but it does not seem to show.我已经搜索了文档,但似乎没有显示。

Misformatting the string, gives an exception that shows that internally this uses the String.Format Method from.Net错误格式化字符串,会给出一个异常,表明在内部这使用了来自 .Net 的String.Format方法

Meaning you can use {0} , {1} , etc to place arguments, with a lot of extra formatting options.这意味着您可以使用{0}{1}等来放置 arguments,并提供许多额外的格式化选项。

For example (not a very realistic case):例如(不是很现实的案例):

Assert.Equals(varExpectedValue, varActualValue, "Expected and actual value are false on iteration {0}", i);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM