src/packages/Shouldly.2.4.0/README.txt
(开头部分) 1KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
Shouldly
========
### How asserting *Should* be
This is the old *Assert* way:
Assert.That(contestant.Points, Is.EqualTo(1337));
For your troubles, you get this message, when it fails:
Expected 1337 but was 0
How it **Should** be:
contestant.Points.ShouldBe(1337);
Which is just syntax, so far, but check out the message when it fails:
contestant.Points should be 1337 but was 0
It might be easy to underestimate how useful this is. Another example, side by side:
Assert.That(map.IndexOfValue("boo"), Is.EqualTo(2)); // -> Expected 2 but was 1
map.IndexOfValue("boo").ShouldBe(2); // -> map.IndexOfValue("boo") should be 2 but was 1
**Shouldly** uses the variables within the *ShouldBe* statement to report on errors, which makes diagnosing easier.
Another example, if you compare two collections:
(new[] { 1, 2, 3 }).ShouldBe(new[] { 1, 2, 4 });
and it fails because they're different, it'll show you the differences between the two collections:
should be
[1, 2, 4]
but was
[1, 2, 3]
difference
[1, 2, *3*]
If you want to check that a particular call does/does not throw an exception, it's as simple as:
Should.Throw<ArgumentOutOfRangeException>(() => widget.Twist(-1));
Then if it chucks a wobbly, you have access to the exception to help debug what the underlying cause was.
Other *Shouldly* features:
####Equality
[ShouldBe] (#equalityShouldBeExample)
[ShouldBeOneOf] (#equalityShouldBeOneOfExample)
[ShouldNotBe] (#equalityShouldNotBeExample)
[ShouldNotBeOneOf] (#equalityShouldNotBeOneOfExample)
[ShouldBeGreaterThan(OrEqualTo)] (#equalityShouldBeGreaterThanExample)
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。