|
Quick Start
The Ideal GUI Unit TestIn an ideal world we could write a unit test like this: [TestMethod]
public void TestMyWindow_in_an_ideal_world() {
var w = new MyWindow(); w.Show(); // Verify_my_window();
w.Close(); } But this won't work. WPF requires an Application instance, another GUI thread and some synchronization between those threads. More importantly, what should Verify_my_window() do? IcuTest answers these problems with only a few extra lines of code: static IcuTest ICU = IcuTestStarter.IcuFromDir(@"c:\test_data"); [TestMethod] public void TestMyWindow() { ICU.Invoke(() => { var w = new MyWindow(); w.Show(); ICU.CheckView(w, "MyWindowTest"); w.Close(); }); } This is a complete GUI test that displays, verifies, and closes a WPF Window.
What Does CheckView() Do?CheckView is the main testing (or Assert) mechanism in IcuTest. It performs a fast bitmap comparison between the current UI snapshot and a previously stored snapshot. Like an Assert, CheckView throws an exception when a test fails. Tests can be executed automatically or interactively. In automatic mode, CheckView simply throws an exception when the bitmaps differ. In interactive mode, the tester is prompted to visually verify which image is correct. The check dialog looks something like this:
The display lets you scrutinize the snapshot, the stored image and the difference between them. You can pass, fail or skip the test.
IcuTests are Proper Unit TestsUnlike typical record-and-playback or "automated" testers, IcuTest let's you directly manipulate the GUI with code. For example, what would happen if we changed MyWindow's DataContext? Well, let's write a test: [TestMethod]
public void TestMyWindow_WithDataContext() {
ICU.Invoke(() => {
var w = new MyWindow(); w.Show(); ICU.CheckView(w, "MyWindowTest");
w.DataContext = new MyViewModel(); ICU.CheckView(w, "MyWindowTest_with_ViewModel");
w.Close(); }); } With IcuTest you can now fully automate your tests; open/close windows, click buttons, select items, enter text, set properties, call methods, etc... The possibilities are endless. See how to make testing even easier...
|