-
Notifications
You must be signed in to change notification settings - Fork 5
TDD
Illegitimis edited this page May 28, 2017
·
6 revisions
- 2010, Freeman & Pryce, Growing Object-Oriented Software, Guided by Tests, 1drv, amzn
- mocking with moq samples
- mocking with moq slides
properties of a | good unit test |
---|---|
atomic | should target a small piece of functionality, hard to maintain otherwise |
deterministic | pass or fail, never inconclusive |
repeatable | consistent with dependent objects changing, time passing and between runs |
order independent & isolated | should not run be forced to run in a specific order, other tests or dependencies should not prevent test passing |
fast | order of ms |
easy to setup | should not be cumbersome |
NUnit | Assert.That |
---|---|
object type and properties |
Is.TypeOf<T>() , Is.InstanceOf<T>() , Has.Property("PropertyName")
|
exceptions | Throws.Exception Throws.TypeOf() .With.Matches(predicate) |
strings | Is.EqualTo("expected") Is.EqualTo("eXpeCTed").IgnoreCase Is.Not.EqualTo("notExpected") |
Numerical values | Is.EqualTo(int) Is.EqualTo(float).Within(tolerance) Is.EqualTo(val).Within(p).Percent Is.Positive / Is.Negative / Is.NaN |
DateTime | Is.EqualTo(dt).Within(ts) Is.EqualTo(dt).Within(v).Milliseconds |
Ranges | Is.GreaterThan(v) / Is.LessThan(v) Is.GreaterThanOrEqualTo(v) Is.InRange(lo,hi) |
Collections | Is.All.Empty Contains.Item(item) Has.Some.ContainsSubstring("sub_str") Has.Exactly(m).EndsWith("suffix") Is.Unique Has.None.EqualTo(val) Is.EquivalentTo(actualCollection) Is.Ordered |
References | Is.SameAs Is.Not.SameAs |
Nulls & booleans |
Is.Not.Empty , Is.Null , Is.True
|