确保值为 true 或 false

要声明值为 true 或 false,请:

Assert.IsFalse(Settings.DoBadThings, "Bad things should not happen, disable DoBadThings.");
Assert.IsTrue(magicNumber =< 42, "The magic number is greater than 42!");

你还可以传递异常消息的格式参数

Assert.IsFalse(myValue > 5, "The value should not be greater than 5, it's currently {0}", myValue);