http://specificity.codeplex.com/ — библиотечка
http://wpfonyx.codeplex.com/ — пример использования на практике
Key features:
∙ discoverable through intellisense
∙ isn't tied to any unit test framework
∙ easily extensible
Попробуем на примерах:
// вместо Assert.InNotNull
[TestMethod]
public void GetView_GivenInstance_ShouldReturnViewInstance()
{
DependencyObject element = new DependencyObject();
View view = View.GetView(element);
Specify.That(view).ShouldNotBeNull();
}
// вместо Assert.AreSame
[TestMethod]
public void GetView_GivenInstance_ShouldSetViewElement()
{
DependencyObject element = new DependencyObject();
View view = View.GetView(element);
Specify.That(view.ViewElement).ShouldBeSameAs(element);
}
// вместо try {} catch { Assert.Fail }
[TestMethod]
public void GetModel_GivenNull_ShouldThrow()
{
Specify.ThatAction(() =>
{
View.GetModel(null);
}).ShouldThrow<ArgumentNullException>();
}
[TestMethod]
public void SomeProperty_GivenValue_ShouldRaisePropertyChanged()
{
DependencyObject element = new DependencyObject();
View view = View.GetView(element);
ViewModelCreatedWithView model = new ViewModelCreatedWithView(view);
PropertyChangedWatcher watcher = new PropertyChangedWatcher(model);
model.SomeProperty = "xyzzy";
Specify.That(watcher).ShouldHaveSeen("SomeProperty");
}