是否有更简单或更小的路要打。
Assert.IsTrue((firstRow.Text ?? "").Contains("SomeText"));
是否有更简单或更小的路要打。
Assert.IsTrue((firstRow.Text ?? "").Contains("SomeText"));
页: 1 The syntax:
Assert.That(firstRow.Text, Does.Contain("SomeText"));
如果你需要核对案文中并未包含某种文字:
Assert.That(firstRow.Text, Does.Not.Contain("SomeText"));
我认为,这些替代物都更好,尽管其数量并不短:
// 1
Assert.IsTrue(firstRow.Text != null && firstRow.Text.Contains("SomeText"));
// 2
Assert.IsNotNull(firstRow.Text);
Assert.IsTrue(firstRow.Text.Contains("SomeText"));
// 3
var text = firstRow.Text;
Assert.IsTrue(text != null && text.Contains("SomeText"));
我认为,“简单”是一个主观术语。 简单地说,对我来说,是指“清晰易读”,而不是“性质之西”。
鉴于该守则似乎属于单位测试的一部分,因此选择第2号最好,因为这样,你就可以从阅读测试结果中看出,该测试是否由于无效或失败而无效,因为价值没有包含预期案文。 否则,为了区分这两种情况,你不得不以夸张的方式重新解释这一检验,看看看操作时间的价值。
“尽可能简单但并非简单” - Albert Einstein
这是短篇的,但坦率地说,我喜欢你原来的法典。
Assert.IsTrue((firstRow.Text + "").Contains("SomeText"));
无。 但你可以写出一种延伸方法:
public static bool SContains(this string source, string query)
{
return source != null && source.Contains(query);
}
我预计,“SomeText”号的插图将出现不同的错误,在这种情况下,最好有两个单位测试,以检验不同的结果。
关于如何使用“强硬”和“NotNull”的方法?
Assert.IsNotNull(firstRow.Text);
StringAssert.Contains(firstRow.Text, "SomeText");
(我假定这涉及单位测试)
According to http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.stringassert(v=vs.100).aspx
强硬产品类别可以用来轻而易举地说明是否有扼杀性。 《全面禁止核试验条约》载有经批准的扼杀状
a 页: 1
这将是一个小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小小的,并且能够有内在的可读性。
If(!string.IsNullOrEmpty(firstRow.Text))
Assert.IsTrue(firstRow.Text.Contains("SomeText"));
我通常会更像以下一点,即时间更长,时间更小,但只是直观,意图是显而易见的。
Assert.IsTrue( !string.IsNullOrWhiteSpace(firstRow.Text))
Assert.IsTrue( firstRow.Text.Contains("SomeText"));
在我对该问题的解释中,空洞是一种错误条件。 我赞成我的说法,即检验的背景是明确的。 如果我想把空洞的扼杀作为有效结果,那么我就把以下因素作为第一个条件,再次明确试验:
Assert.IsNotNull(firstRow.Text)
对我来说,这比缩短法典更为重要。 在我(或其他人)回头修改法典的一个月里,检验的意图是显而易见的。 在原始问题上,情况并非如此。
What is the use of default keyword in C#? Is it introduced in C# 3.0 ?
I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...
I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...
I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...
I have two EF entities. One has a property called HouseNumber. The other has two properties, one called StartHouseNumber and one called EndHouseNumber. I want to create a many to many association ...
How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...
Since I cannot order my dictionary, what is the best way of going about taking key value pairs and also maintaing an index?
Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...