In this article, we will demonstrate getting started with xUnit.net for UWP, showing you how to write and run your first set of unit tests.
File -> New
Project and create a Blank UWP project:
xunit.runner.devices
package. If you want unit tests in this project, also add xunit
:
App.xaml
and App.xaml.cs
with the following (using your namespace in x:Class
):
<ui:RunnerApplication
x:Class="UwpTestRunner.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ui="using:Xunit.Runners.UI"
RequestedTheme="Light">
</ui:RunnerApplication>
using System.Reflection;
using Xunit.Runners.UI;
namespace UwpTestRunner
{
sealed partial class App : RunnerApplication
{
protected override void OnInitializeRunner()
{
// tests can be inside the main assembly
AddTestAssembly(GetType().GetTypeInfo().Assembly);
// otherwise you need to ensure that the test assemblies will
// become part of the app bundle
// AddTestAssembly(typeof(PortableTests).GetTypeInfo().Assembly);
}
}
}
MainPage.xaml
and MainPage.xaml.cs
:
App.xaml.cs
to include the assembly containing your tests
xunit.runner.json
file as Content
to specify runner configuration