Welcome to Habanero Land!   Register  |  Login
You are here:   Blogs
  So, why do you need to register to download Habanero and access the additional materials? 
The success of any open source project is based on the community built around it. So go ahead, register / login and get involved!
Dec
16
Thu
Posted By Andrew on Thursday, December 16, 2010
415 Views


This is the third blog in a series of blogs I have put together whilst trying to find a solution for unit testing WPF Bindings.

Ok so I have yet to find what I am looking for. AvalonTestRunner got half way there. BindingFinder looked promising, but got horribly complicated very quickly. Back to the internet for yet another look. After some more looking and after chatting with the guys in the office I have decided to give the White Framework a go.

White is a framework for doing automation testing of Windows style applications. My approach to testing the bindings using White will need to be slightly different. Instead of trying to test for the existence of a binding itself, I am going to have to compare the value of the business object with the value displayed in the control, on the WPF window, to which object property should be bound.

I downloaded the latest version of White (white.codeplex.com ) and extracted the files. I added references to the White.Core, White.NUnit, Bricks and Bricks.Framework to my test project and started writing some tests. The first test was simply to see if I could start my application and the close it correctly.

        [Test]
        public void Test_CanLoadApplication_With_White()
        {
            //---------------Set up test pack-------------------
            var app = Application.Launch(@"..\..\..\ReplaceItWpf\bin\Debug\ReplaceItWpf.exe");
            //---------------Assert Precondition----------------
 
            //---------------Execute Test ----------------------
 
            //---------------Test Result -----------------------
            Assert.IsNotNull(app);
            app.Kill();
        }

This was pretty straight forward. Next test, can I get a window.

        [Test]
        public void Test_CanGetMainWindow()
        {
            //---------------Set up test pack-------------------
            var app = Application.Launch(@"..\..\..\ReplaceItWpf\bin\Debug\ReplaceItWpf.exe");
            var mainWindow = app.GetWindow("MainWindow", InitializeOption.NoCache);
            Assert.IsNotNull(mainWindow);
 
            //---------------Assert Precondition----------------
 
            //---------------Execute Test ----------------------
 
            //---------------Test Result -----------------------
            Assert.IsNotNull(app);
            app.Kill();
        }

That wasn’t too painful either. Up until this point things were looking promising. Then the wheels came off. The next task was to create a business object to be used as the DataContext on a WPF Window or UserControl so that I had something to test against. This just isn’t going to work. The business object is created in the unit test and the application is opened as an application in a totally separate process let alone separate thread. The option of having to load the data from a configuration file or some other stored data source just doesn’t appeal to me. It doesn’t feel much like a unit test at all when you get to that stage. I think it’s time once again to get back onto the internet and see what else is out there.

Categories

 Top Viewed
 Habanero Cloud
 Archive
 

This website is best viewed in Internet Explorer 7 & 8; Firefox 3.6.11; Opera 10.63; & Safari 4.