How to write unit tests using Unit Driven for windows phone 7 application development?

249 views Asked by At

I have been searching Unit Test framework that is capable of testing asynchronous functional calls in Windows Phone 7 application development. Yes, Unit driven was the one pop up in my sight. However, that framework was not developer friendly as NUnit(which unfortunately cannot test asynch methods). On the internet, people has been using UD for Unit Testing. Could someone drop in and offer some advice?

My specific questions are:

1) Where do I include the following initialisation code?

private void Application_Startup(object sender, StartupEventArgs e)
{
      this.RootVisual = new UnitDriven.TestEngine(Assembly.GetExecutingAssembly());
}

2) How do I write test cases for UD? With NUnit, I can write test cases along with my application and NUnit loads my dll and execute tests. I have tried to put in my application but Visual Studio 2010 express always complain that it cannot find symbol GetContext()

UnitTestContext context = GetContext();

3) There were three dlls coming with UD. UnitDrivenLight, UnitDrivenPhone, UnitDrivenNet... So, what are the roles of UnitDrivenLight and UnitDrivenPhone? Very confusing at the moment.

Thanks

Simo

2

There are 2 answers

0
Simoscofield On

In the end, with Szalay's hints, I moved to use Microsoft's sliverlight test framework for asynchronous tests, here's the example test class:

namespace TestApp
{
    using System.Threading;
    using Microsoft.Silverlight.Testing;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    /// <summary>
    /// An example test class
    /// </summary>
    [TestClass]
    public class ExampleTestClass : SilverlightTest
    {

        /// <summary>
        /// Sample asynchronous test
        /// </summary>
        [TestMethod, Tag("Asynchronous Test"), Asynchronous]
        public void SampleAsynchronousTest()
        {
            ThreadPool.QueueUserWorkItem(o =>
                {
                    for (int j = 0; j < 10000; j++){}
                    CheckResult(10);
                });
        }

        /// <summary>
        /// Check result
        /// </summary>
        /// <param name="variable">result</param>
        private void CheckResult(int variable)
        {
            Assert.IsTrue(variable == 10);
            EnqueueTestComplete();
        }
    }
}
11
Richard Szalay On

I've not used UnitDriven myself, but I've had success with the testing framework that ships with the Windows Phone Toolkit (which supports asynchronous tests).

In fact, I've created a modified version which adds command line support. It's in NuGet as wp7-ci (the custom MSBuild task complicates manual installation).