断言与条件 [英] c# - Asserting with OR condition
本文介绍了断言与条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在检查一个字符串中是否包含三个字符
i am checking a string for three characters
Assert.AreEqual(myString.Substring(3,3), "DEF", "Failed as DEF was not observed");
这里的东西可以是DEF
或RES
,现在要处理此事,我能想到的是以下
the thing is here it can be DEF
or RES
, now to handle this what i can think of is the following
bool check = false;
if( myString.Substring(3,3) == "DEF" || myString.Substring(3,3) == "RED" )
check = true;
Assert.IsTrue(check,"Failed");
Console.WriteLine(""Passed);
是我可以在Assert中使用某些OR东西的一种方式
p.s我正在编写单元测试&是的,我将改为使用三元运算符....
p.s i'm writing unit test & yes i will use ternary operator instead....
推荐答案
Assert.IsTrue((myString.Substring(3,3) == "DEF" || myString.Substring(3,3) == "RED")?true:false,"Failed");
这篇关于断言与条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文