From WPF functional Unit Tests to Specifications using MSpec and White
I am in the train back home and wanted to try out quickly to migrate our WPF functional tests written has Unit Tests to BDD Specifications.
Here is the code I started from, pure Unit Test using NUnit and White
[Test]
public void Opening_Valid_VersionZip()
{
OpenAndWait("Product.zip");
Assert.That(MainWindow.Title.Equals("Product.zip - Innoveo Skye® Editor"));
Assert.That(Status.Text.Equals("product"));
Assert.That(ProductTree.Nodes.Count >= 1);
Assert.IsFalse(SplashScreen.Visible);
Assert.IsTrue(SaveButton.Enabled);
Assert.IsTrue(ActivateButton.Enabled);
}
public void Opening_Valid_VersionZip()
{
OpenAndWait("Product.zip");
Assert.That(MainWindow.Title.Equals("Product.zip - Innoveo Skye® Editor"));
Assert.That(Status.Text.Equals("product"));
Assert.That(ProductTree.Nodes.Count >= 1);
Assert.IsFalse(SplashScreen.Visible);
Assert.IsTrue(SaveButton.Enabled);
Assert.IsTrue(ActivateButton.Enabled);
}
Now the same functional test written as a BDD specification using MSpec
[Subject("OpenVersionZip")]
public class when_user_open_valid_versionzip : MainWindowViewSpecs
{
Establish context = () => {};
Because of = () => OpenAndWait("Product.zip");
It should_display_mainwindow_title_correctly = () =>
MainWindow.Title.ShouldEqual("Product.zip - Innoveo Skye® Editor");
It should_display_status_correctly = () =>
Status.Text.ShouldEqual("product");
It should_display_the_product_tree = () =>
ProductTree.Nodes.ShouldNotBeNull();
It should_hide_the_splashscreen = () =>
SplashScreen.Visible.ShouldBeFalse();
It should_enable_save_button = () =>
SaveButton.Enabled.ShouldBeTrue();
It should_enable_activate_button = () =>
ActivateButton.Enabled.ShouldBeTrue();
}
public class when_user_open_valid_versionzip : MainWindowViewSpecs
{
Establish context = () => {};
Because of = () => OpenAndWait("Product.zip");
It should_display_mainwindow_title_correctly = () =>
MainWindow.Title.ShouldEqual("Product.zip - Innoveo Skye® Editor");
It should_display_status_correctly = () =>
Status.Text.ShouldEqual("product");
It should_display_the_product_tree = () =>
ProductTree.Nodes.ShouldNotBeNull();
It should_hide_the_splashscreen = () =>
SplashScreen.Visible.ShouldBeFalse();
It should_enable_save_button = () =>
SaveButton.Enabled.ShouldBeTrue();
It should_enable_activate_button = () =>
ActivateButton.Enabled.ShouldBeTrue();
}
And the output in ReSharper MSpec plugin
Which one do you prefer? I personally have made my choice.