,

Creating a Test Class

To create a test class, add a new class to your test project. Then add the following two using statements to the top of the class:

using Microsoft.Phone.Testing;
using Microsoft.VisualStudio.TestTools.UnitTesting;

Test-related attributes and assertion types can be found within the namespace Microsoft.VisualStudio.TestTools.UnitTesting. Even if you have not used the Visual Studio UTF before, it is easy to pick up because the attribute names are fairly self-descriptive.

Tests consist of test classes and test methods. The UTF relies on metadata, provided by attributes, for identifying unit test classes and methods at runtime. To indicate that a class is a unit test class, decorate it with the TestClassAttribute, as shown in the following example:

[TestClass]
public class FirstTest : WorkItemTest
{
    [TestMethod]
    [Description("A first unit test.")]
    public void ShouldAlwaysPass()
    {
        Assert.IsTrue(true);
    }
}

To run the test, set the test project as the startup project by right-clicking the project node in the Visual Studio Solution Explorer and selecting Set as Startup Project. Then debug the solution by selecting Start Debugging from the Debug menu, or by pressing F5. When the app starts, the tag expressions editor is presented (see Figure 24.2).

Image

FIGURE 24.2 The tag expressions editor.

The tag expressions editor allows you to run all or a subset of the tests. Tap the application bar’s play button to commence testing.

When the test completes, a review page is presented in the test harness (see Figure 24.3).

Image

FIGURE 24.3 A passed unit test.

The test harness enables you to drill down to see the details of each test method. The content of the test method’s Description attribute is presented beneath the test method’s name.

Tests run on a single thread and are executed within the Windows Phone sandboxed environment.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.64.94