1
2
3
4
5
6

A Cheat Sheet for Unit Testing Silverlight Apps on Windows Phone 7

I've been planning on writing a quick overview of the basics of unit testing in Silverlight for a while now. Since Windows Phone 7 is the hot topic now, and there are a few quirks with using the Silverlight Unit Test Framework with it, I figured now would be a good chance to write a blog entry covering both. If you're just looking for the cheat sheet relative to both Silverlight and WP7 unit tests, then skip the first section on setting up the test harness on WP7.

Setting up the Test Harness for WP7
To get started, you'll need the Silverlight Unit Test Framework tweaked for Windows Phone 7 from Jeff Wilcox's blog here. I've attached the binaries to this post as well (SL3_UTF_May.zip).

Once you have the binaries, you'll want to create a new test harness project. Do this by creating a new project in your solution of type 'Windows Phone Application'. In the sample attached to this post I'm calling my test project SampleTestProject.

Next, add references to the two Silverlight Unit Test Framework DLLs*:
Microsoft.Silverlight.Testing.dll
Microsoft.VisualStudio.QualityTools.UnitTesting.Silverlight.dll

* you will get a warning about referencing Silverlight 3 assemblies, click 'yes' when asked if you want to continue

Because of recent changes in WP7, you can no longer set the root visual in the App.xaml.cs like normal. Instead, you'll setup the test page in the Loaded() event of your MainPage.xaml.cs in your test project. The following code hides the SystemTray on the phone (the bar at the top of the screen) which otherwise would cover up the top of test results screen, and hooks up the back button to allow you to return back from drilling into test results.

using Microsoft.Phone.Shell;
using Microsoft.Silverlight.Testing;
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
    SystemTray.IsVisible = false;

    var testPage = UnitTestSystem.CreateTestPage() as IMobileTestPage;
    BackKeyPress += (x, xe) => xe.Cancel = testPage.NavigateBack();
    (Application.Current.RootVisual as PhoneApplicationFrame).Content = testPage;            
}

(click 'read more' to keep reading..)

Now that we've setup the test page, we can start creating test classes and test methods. Here is a sample set of simple tests:

[TestClass]
public class BasicTests : SilverlightTest
{
    [TestMethod]
    public void AlwaysPass()
    {
        Assert.IsTrue(true, "method intended to always pass");
    }
             
    [TestMethod]
    [Description("This test always fails intentionally")]
    public void AlwaysFail()
    {
        Assert.IsFalse(true, "method intended to always fail");
    }
}

And this is what the results look like:


click for larger size

Basically you drill into your test results from an overview of all test classes, to a specific set of test methods, to the results of a specific test. On the test results screen you should notice the optional [Description] attribute for the failing test is displayed as well as the failed Assert text, both are highlighted in green in the screenshot above.

Tagging Tests
By using the [Tag("tagText")] attribute on a test method or class, you can choose a subset of tests to run when the test harness launches. You'll notice when the WP7 test harness launches you can choose to only run tests with a certain tag, a certain set of tags, or not run tests with specific tags. Here is an example of tagging a TestMethod:

[TestMethod]
[Tag("SubsetTag")]
public void AlwaysPass()
{
    Assert.IsTrue(true, "method intended to always pass");
}

Testing Non-Public Methods
Frequently you will want to write unit tests against methods that aren't publicly exposed. Rather than make these private methods public, you can specify assemblies to which the methods are exposed. In other words, you can make your classes allow your test classes to access them but keep them private to everyone else.

All you have to do is edit the AssemblyInfo.cs of the assembly you want to expose to your tests, and add the following line (where "SampleTestProject" is the name of your test assembly):

[assembly: InternalsVisibleTo("SampleTestProject")]

Once you make this change and rebuild you should notice that any methods marked as 'internal' will now be accessible. If you are using private methods, change them to internal.

Testing Asynchronous Methods
To test asynchronous methods you'll first have to make sure your TestClass inherits from SilverlightTest. Next, you'll need to mark the test method as [Asynchronous]. Finally, you'll have to call EnqueueTestComplete() to tell the test when it has completed - if you don't call this then the test will never complete. In the example below you'll see we call EnqueueTestComplete() after the callback has returned and we have done our assertions.

[TestClass]
public class AsyncTests : SilverlightTest
{
    [Asynchronous]
    [TestMethod]
    public void AsyncAppendStringTest()
    {
        var appendStrings = new List<string>() { "hello", "there" };

        StringJoiner.AsyncAppendStringsWithDashes(appendStrings, (returnString) =>
            {
                Assert.IsTrue(string.Compare(returnString, "hello-there") == 0);
                EnqueueTestComplete();
            });
    }
}

Testing for Expected Exceptions
In our example, we want our method to throw a ArgumentException when the List passed in is empty, but we want it to throw a ArgumentNullException when the List passed in is null. Implementing tests to check that these exceptions are thrown is pretty straightforward using the [ExpectedException] attribute, here is an example:

[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void AppendStringsWithDashes_EmptyCollection_ExpectedException()
{
    StringJoiner.AppendStringsWithDashes(new List<string>());
}

[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void AppendstringsWithDashes_NullCollection_ExpectedException()
{
    StringJoiner.AppendStringsWithDashes(null);
}

Using the Exclusive Attribute
Normally in the Silverlight Unit Test Framework you can use the [Exclusive] attribute on either your TestClass, or specific TestMethods to make them be the only class or method run. While this compiles fine on WP7, it does not appear to currently work. If someone else gets them to work please let me know. Here is a code sample that works in the normal Silverlight Unit Test Framework:

[Exclusive]
[TestMethod]
public void AlwaysPass()
{
    Assert.IsTrue(true, "method intended to always pass");
}

Using the Ignore Attribute
If you want to prevent a certain set of tests from running, you can add the [Ignore] attribute on your TestClass, or to individual TestMethods. Be sure to note that the total number of tests listed in the unit test harness will not change, but the tests will be ignored and not run.

[Ignore]
[TestMethod]
public void AlwaysPass()
{
    Assert.IsTrue(true, "method intended to always pass");
}

Closing
All these examples make up a cheat sheet that I rely on pretty heavily. I usually keep code snippets like this in Evernote, hopefully posting them here will help you have a quick reference to some of the basics of unit testing with the Silverlight Unit Test Framework. Check out the attached solution to see the full sample code - be sure to set the 'SampleTestProject' as the startup project.

AttachmentSize
SL3_UTF_May.zip451.68 KB
WP7UnitTestsSampleApp.zip481.15 KB

Comments

Hi,
Is there any way I can run the test cases from commandline? For e.g. using mstest

Thanks in advance!
--Tanveer


1) The test names are chopped, and there's no scrolling to see the test name
2) Cannot change orientation to ease (1)

How would this framework deal with thousands of tests for a more complicated application, such as a real world business application?

This is not critique, I'm just genuinly interested in how I'm supposed to work this framework. I've got it to compile and run, but the way we run TDD here, the tests quickly add up to the hundreds within a matter of a week or two, thousands over a month, etc. Looks to me like this framework is only designe for shallow, very superficial tests, and that you can only, practically run tagged tests, not all.


Pedro - please look at my last comment for a few links that might be helpful. If you're doing hundreds/thousands of tests then you should probably look into test automation and running the tests as part of your build scripts, and not be trying to analyze your test results inside of an emulator. I'm not sure how feasible that is currently, but I can assure you you aren't the only person who will need fully-automated testing for WP7 apps/libraries.


Thanks for great article.
I got a courage to try TDD on Wp7.
But can you show how to select tagged test only?
[Exclusive] attribute did not work when I tried your article.

Thanks.


tapfish - it doesnt' seem like the [Exclusive] attribute is working currently on the WP7 test harness. Instead you can tag your tests - [Tag("SubsetTag")] - and when the test harness runs, click on 'Touch to create tag', type in your tag "SubsetTag" and click on "Use tag". That will run just the tests tagged "SubsetTag", and will add "SubsetTag" to your recent list of tags used in the test harness so that next time you run your tests you can just click on that tag to run that set of tests.


Test framework is good.
But, test framework have some error. When debugging, generated exception.

Below describe some exception.
My visual studio version is Express for Windows Phone 'Version 4.0.30319'

Have any idea ? Thanks.

=================================================
System.Windows.Data Error: BindingExpression path error: 'Name' property not found on 'Microsoft.Silverlight.Testing.Client.TestRunData' 'Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736). BindingExpression: Path='Name' DataItem='Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736); target element is 'System.Windows.Controls.ContentControl' (Name=''); target property is 'Content' (type 'System.Object')..
System.Windows.Data Error: BindingExpression path error: 'TestClasses' property not found on 'Microsoft.Silverlight.Testing.Client.TestRunData' 'Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736). BindingExpression: Path='TestClasses' DataItem='Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736); target element is 'System.Windows.Controls.ListBox' (Name=''); target property is 'ItemsSource' (type 'System.Collections.IEnumerable')..
System.Windows.Data Error: BindingExpression path error: 'Name' property not found on 'Microsoft.Silverlight.Testing.Client.TestRunData' 'Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736). BindingExpression: Path='Name' DataItem='Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736); target element is 'System.Windows.Controls.ContentControl' (Name=''); target property is 'Content' (type 'System.Object')..
System.Windows.Data Error: BindingExpression path error: 'TestMethods' property not found on 'Microsoft.Silverlight.Testing.Client.TestRunData' 'Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736). BindingExpression: Path='TestMethods' DataItem='Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736); target element is 'System.Windows.Controls.ListBox' (Name=''); target property is 'ItemsSource' (type 'System.Collections.IEnumerable')..
System.Windows.Data Error: BindingExpression path error: 'Parent' property not found on 'Microsoft.Silverlight.Testing.Client.TestRunData' 'Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736). BindingExpression: Path='Parent.Name' DataItem='Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736); target element is 'Microsoft.Silverlight.Testing.Client.AdvancedButton' (Name=''); target property is 'Content' (type 'System.Object')..
System.Windows.Data Error: BindingExpression path error: 'Name' property not found on 'Microsoft.Silverlight.Testing.Client.TestRunData' 'Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736). BindingExpression: Path='Name' DataItem='Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736); target element is 'System.Windows.Controls.ContentControl' (Name=''); target property is 'Content' (type 'System.Object')..
A first chance exception of type 'System.InvalidOperationException' occurred in System.Windows.dll
System.Windows.Data Error: 'MS.Internal.Data.DynamicValueConverter' converter failed to convert value 'Microsoft.Silverlight.Testing.Client.TestRunData' (type 'Microsoft.Silverlight.Testing.Client.TestRunData'); BindingExpression: Path='' DataItem='Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736); target element is 'System.Windows.Controls.TextBlock' (Name=''); target property is 'Visibility' (type 'System.Windows.Visibility').. System.InvalidOperationException: Can't convert type Microsoft.Silverlight.Testing.Client.TestRunData to type System.Windows.Visibility.
at MS.Internal.Data.DefaultValueConverter.Create(Type sourceType, Type targetType, Boolean targetToSource)
at MS.ISystem.Windows.Data Error: BindingExpression path error: 'Parent' property not found on 'Microsoft.Silverlight.Testing.Client.TestRunData' 'Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736). BindingExpression: Path='Parent.Name' DataItem='Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736); target element is 'System.Windows.Controls.TextBlock' (Name=''); target property is 'Text' (type 'System.String')..
System.Windows.Data Error: BindingExpression path error: 'Name' property not found on 'Microsoft.Silverlight.Testing.Client.TestRunData' 'Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736). BindingExpression: Path='Name' DataItem='Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736); target element is 'System.Windows.Controls.TextBlock' (Name=''); target property is 'Text' (type 'System.String')..
A first chance exception of type 'System.InvalidOperationException' occurred in System.Windows.dll
System.Windows.Data Error: 'MS.Internal.Data.DynamicValueConverter' converter failed to convert value 'Microsoft.Silverlight.Testing.Client.TestRunData' (type 'Microsoft.Silverlight.Testing.Client.TestRunData'); BindingExpression: Path='' DataItem='Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736); target element is 'System.Windows.Controls.StackPanel' (Name=''); target property is 'Visibility' (type 'System.Windows.Visibility').. System.InvalidOperationException: Can't convert type Microsoft.Silverlight.Testing.Client.TestRunData to type System.Windows.Visibility.
at MS.Internal.Data.DefaultValueConverter.Create(Type sourceType, Type targetType, Boolean targetToSource)
at MS.System.Windows.Data Error: BindingExpression path error: 'HasDescriptionVisibility' property not found on 'Microsoft.Silverlight.Testing.Client.TestRunData' 'Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736). BindingExpression: Path='HasDescriptionVisibility' DataItem='Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736); target element is 'System.Windows.Controls.TextBlock' (Name=''); target property is 'Visibility' (type 'System.Windows.Visibility')..
System.Windows.Data Error: BindingExpression path error: 'Description' property not found on 'Microsoft.Silverlight.Testing.Client.TestRunData' 'Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736). BindingExpression: Path='Description' DataItem='Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736); target element is 'System.Windows.Controls.TextBlock' (Name=''); target property is 'Text' (type 'System.String')..
System.Windows.Data Error: BindingExpression path error: 'Result' property not found on 'Microsoft.Silverlight.Testing.Client.TestRunData' 'Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736). BindingExpression: Path='Result.Result' DataItem='Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736); target element is 'System.Windows.Controls.TextBlock' (Name=''); target property is 'Text' (type 'System.String')..
A first chance exception of type 'System.InvalidOperationException' occurred in System.Windows.dll
System.Windows.Data Error: 'MS.Internal.Data.DynamicValueConverter' converter failed to convert value 'True' (type 'System.Boolean'); BindingExpression: Path='Passed' DataItem='Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736); target element is 'System.Windows.Controls.TextBlock' (Name=''); target property is 'FontWeight' (type 'System.Windows.FontWeight').. System.InvalidOperationException: Can't convert type System.Boolean to type System.Windows.FontWeight.
at MS.Internal.Data.DefaultValueConverter.Create(Type sourceType, Type targetType, Boolean targetToSource)
at MS.Internal.Data.DynamicValueConverter.EnsureConverter(Type sourceType, Type targetType)
at MS.Internal.DaSystem.Windows.Data Error: BindingExpression path error: 'Parent' property not found on 'Microsoft.Silverlight.Testing.Client.TestRunData' 'Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736). BindingExpression: Path='Parent.Parent.Name' DataItem='Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736); target element is 'System.Windows.Controls.TextBlock' (Name=''); target property is 'Text' (type 'System.String')..
System.Windows.Data Error: BindingExpression path error: 'Parent' property not found on 'Microsoft.Silverlight.Testing.Client.TestRunData' 'Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736). BindingExpression: Path='Parent.Namespace' DataItem='Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736); target element is 'System.Windows.Controls.TextBlock' (Name=''); target property is 'Text' (type 'System.String')..
System.Windows.Data Error: BindingExpression path error: 'Parent' property not found on 'Microsoft.Silverlight.Testing.Client.TestRunData' 'Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736). BindingExpression: Path='Parent.Name' DataItem='Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736); target element is 'System.Windows.Controls.TextBlock' (Name=''); target property is 'Text' (type 'System.String')..
System.Windows.Data Error: BindingExpression path error: 'Name' property not found on 'Microsoft.Silverlight.Testing.Client.TestRunData' 'Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736). BindingExpression: Path='Name' DataItem='Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736); target element is 'System.Windows.Controls.TextBlock' (Name=''); target property is 'Text' (type 'System.String')..
System.Windows.Data Error: BindingExpression path error: 'Result' property not found on 'Microsoft.Silverlight.Testing.Client.TestRunData' 'Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736). BindingExpression: Path='Result.Started' DataItem='Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736); target element is 'System.Windows.Controls.TextBlock' (Name=''); target property is 'Text' (type 'System.String')..
System.Windows.Data Error: BindingExpression path error: 'Result' property not found on 'Microsoft.Silverlight.Testing.Client.TestRunData' 'Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736). BindingExpression: Path='Result.Finished' DataItem='Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736); target element is 'System.Windows.Controls.TextBlock' (Name=''); target property is 'Text' (type 'System.String')..
System.Windows.Data Error: BindingExpression path error: 'ReadableElapsedTime' property not found on 'Microsoft.Silverlight.Testing.Client.TestRunData' 'Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736). BindingExpression: Path='ReadableElapsedTime' DataItem='Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736); target element is 'System.Windows.Controls.TextBlock' (Name=''); target property is 'Text' (type 'System.String')..
A first chance exception of type 'System.InvalidOperationException' occurred in System.Windows.dll
System.Windows.Data Error: 'MS.Internal.Data.DynamicValueConverter' converter failed to convert value 'Microsoft.Silverlight.Testing.Client.TestRunData' (type 'Microsoft.Silverlight.Testing.Client.TestRunData'); BindingExpression: Path='' DataItem='Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736); target element is 'System.Windows.Controls.StackPanel' (Name=''); target property is 'Visibility' (type 'System.Windows.Visibility').. System.InvalidOperationException: Can't convert type Microsoft.Silverlight.Testing.Client.TestRunData to type System.Windows.Visibility.
at MS.Internal.Data.DefaultValueConverter.Create(Type sourceType, Type targetType, Boolean targetToSource)
at MS.System.Windows.Data Error: BindingExpression path error: 'KnownBugs' property not found on 'Microsoft.Silverlight.Testing.Client.TestRunData' 'Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736). BindingExpression: Path='KnownBugs' DataItem='Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736); target element is 'System.Windows.Controls.StackPanel' (Name=''); target property is 'Visibility' (type 'System.Windows.Visibility')..
System.Windows.Data Error: BindingExpression path error: 'KnownBugs' property not found on 'Microsoft.Silverlight.Testing.Client.TestRunData' 'Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736). BindingExpression: Path='KnownBugs' DataItem='Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736); target element is 'System.Windows.Controls.ItemsControl' (Name=''); target property is 'ItemsSource' (type 'System.Collections.IEnumerable')..
System.Windows.Data Error: BindingExpression path error: 'FixedBugs' property not found on 'Microsoft.Silverlight.Testing.Client.TestRunData' 'Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736). BindingExpression: Path='FixedBugs' DataItem='Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736); target element is 'System.Windows.Controls.StackPanel' (Name=''); target property is 'Visibility' (type 'System.Windows.Visibility')..
System.Windows.Data Error: BindingExpression path error: 'FixedBugs' property not found on 'Microsoft.Silverlight.Testing.Client.TestRunData' 'Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736). BindingExpression: Path='FixedBugs' DataItem='Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736); target element is 'System.Windows.Controls.ItemsControl' (Name=''); target property is 'ItemsSource' (type 'System.Collections.IEnumerable')..
System.Windows.Data Error: BindingExpression path error: 'SimplifiedExpectedExceptionName' property not found on 'Microsoft.Silverlight.Testing.Client.TestRunData' 'Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736). BindingExpression: Path='SimplifiedExpectedExceptionName' DataItem='Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736); target element is 'System.Windows.Controls.StackPanel' (Name=''); target property is 'Visibility' (type 'System.Windows.Visibility')..
System.Windows.Data Error: BindingExpression path error: 'SimplifiedExpectedExceptionName' property not found on 'Microsoft.Silverlight.Testing.Client.TestRunData' 'Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736). BindingExpression: Path='SimplifiedExpectedExceptionName' DataItem='Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736); target element is 'System.Windows.Controls.StackPanel' (Name=''); target property is 'Visibility' (type 'System.Windows.Visibility')..
System.Windows.Data Error: BindingExpression path error: 'SimplifiedExpectedExceptionName' property not found on 'Microsoft.Silverlight.Testing.Client.TestRunData' 'Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736). BindingExpression: Path='SimplifiedExpectedExceptionName' DataItem='Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736); target element is 'System.Windows.Controls.TextBlock' (Name=''); target property is 'Text' (type 'System.String')..
System.Windows.Data Error: BindingExpression path error: 'Result' property not found on 'Microsoft.Silverlight.Testing.Client.TestRunData' 'Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736). BindingExpression: Path='Result.Exception' DataItem='Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736); target element is 'System.Windows.Controls.StackPanel' (Name=''); target property is 'Visibility' (type 'System.Windows.Visibility')..
System.Windows.Data Error: BindingExpression path error: 'SimplifiedExceptionName' property not found on 'Microsoft.Silverlight.Testing.Client.TestRunData' 'Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736). BindingExpression: Path='SimplifiedExceptionName' DataItem='Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736); target element is 'System.Windows.Controls.TextBlock' (Name=''); target property is 'Text' (type 'System.String')..
System.Windows.Data Error: BindingExpression path error: 'Result' property not found on 'Microsoft.Silverlight.Testing.Client.TestRunData' 'Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736). BindingExpression: Path='Result.Exception.Message' DataItem='Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736); target element is 'System.Windows.Controls.TextBlock' (Name=''); target property is 'Text' (type 'System.String')..
System.Windows.Data Error: BindingExpression path error: 'SimplifiedExceptionStackTrace' property not found on 'Microsoft.Silverlight.Testing.Client.TestRunData' 'Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736). BindingExpression: Path='SimplifiedExceptionStackTrace' DataItem='Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736); target element is 'System.Windows.Controls.TextBlock' (Name=''); target property is 'Text' (type 'System.String')..
System.Windows.Data Error: BindingExpression path error: 'Result' property not found on 'Microsoft.Silverlight.Testing.Client.TestRunData' 'Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736). BindingExpression: Path='Result.Exception.InnerException' DataItem='Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736); target element is 'System.Windows.Controls.StackPanel' (Name=''); target property is 'Visibility' (type 'System.Windows.Visibility')..
System.Windows.Data Error: BindingExpression path error: 'Result' property not found on 'Microsoft.Silverlight.Testing.Client.TestRunData' 'Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736). BindingExpression: Path='Result.Exception.InnerException' DataItem='Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736); target element is 'System.Windows.Controls.TextBlock' (Name=''); target property is 'Text' (type 'System.String')..
'taskhost.exe' (Managed): Loaded '\Applications\Install\1AA2091E-A043-493F-9AF1-A4C3E4245529\Install\Microsoft.VisualStudio.QualityTools.UnitTesting.Silverlight.dll'
TestInfrastructure: Initialization of UnitTestHarness
Information: Tag expression "All" is in use.
TestInfrastructure: All
TestExecution: Unit Testing
'taskhost.exe' (Managed): Loaded '\Applications\Install\1AA2091E-A043-493F-9AF1-A4C3E4245529\Install\FancyStringManipulaitons.dll', Symbols loaded.
TestExecution: TestGroupSampleTestProject starting
TestExecution: AsyncTests
TestExecution: AsyncAppendStringTest
A first chance exception of type 'Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException' occurred in Microsoft.VisualStudio.QualityTools.UnitTesting.Silverlight.dll
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll
A first chance exception of type 'System.InvalidOperationException' occurred in System.Windows.dll
System.Windows.Data Error: 'MS.Internal.Data.DynamicValueConverter' converter failed to convert value 'False' (type 'System.Boolean'); BindingExpression: Path='Passed' DataItem='Microsoft.Silverlight.Testing.Client.TestRunData' (HashCode=127111736); target element is 'System.Windows.Controls.TextBlock' (Name=''); target property is 'FontWeight' (type 'System.Windows.FontWeight').. System.InvalidOperationException: Can't convert type System.Boolean to type System.Windows.FontWeight.
at MS.Internal.Data.DefaultValueConverter.Create(Type sourceType, Type targetType, Boolean targetToSource)
at MS.Internal.Data.DynamicValueConverter.EnsureConverter(Type sourceType, Type targetType)
at MS.Internal.DTestExecution: BasicTests
TestExecution: AlwaysFail
Error: Exception: Type "Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException" Message "Assert.IsFalse failed. method intended to always fail"
TestResult: BasicTests.AlwaysFail
TestExecution: AlwaysPass
'taskhost.exe' (Managed): Loaded 'System.SR.dll'
A first chance exception of type 'System.ArgumentException' occurred in FancyStringManipulaitons.dll
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll
TestExecution: AppendStringsWithDashes_EmptyCollection_ExpectedException
A first chance exception of type 'System.ArgumentNullException' occurred in FancyStringManipulaitons.dll
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll
TestExecution: AppendstringsWithDashes_NullCollection_ExpectedException
TestExecution: TestInternalMethod


Does this work with the RTM versions of the tools? When I try and create the test page, I get:

System.MissingMethodException: Could not load type 'Microsoft.Silverlight.Testing.UnitTestSystem' from assembly 'Microsoft.Silverlight.Testing, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35'.\r\n at System.Windows.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)\r\n at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)\r\n"


I definitely had the wrong binaries. But, after updating, I still have the same problem. Both of my .dlls are v3.0.31115.2022 and I followed your instructions exactly.

Is that the correct version number?

Does this work in the Express Edition?


I had the same problem before. The way I fix it is download the latest binaries. After making sure the WP7 project references the new binaries, you need to restart the emulator and run "dev /resetskippkgs". This is to guarantee that the project will really reference the new binaries in the WP7 emulator.


How about VS2010 Express WP?

I have exactly the same problem as Eddie. I am sure it works on commercial Visual Studio versions but has anyone succeeded to get this working on Visual Studio 2010 Express for Windows Phone?


what does this give the developer over standard unit testing with the VS test project ?

I thought it would give the ability to load pages/UI elements within the context of the emulator, but
var page = new MyPage();
page is never "loaded" even
page.Loaded += ((s,e) {
Assert.AreEqual("test",page.ApplicationTitle.Text);
}

never fires (even with all the async decoration and Enque calls).

nor does it work of non pages such as UserControls.

bool isReady = false;
var control = new ControlSUT();
control.Loaded += ((s, e) =>
{
isReady = true;
});
EnqueueConditional(() => isReady);
EnqueueCallback(
() => Assert.AreEqual("test", control.Tag.ToString()));
EnqueueTestComplete();

in which case I can just add a standard Test project and test all my VM and non UI.