Skip to main content
A newer version of this page is available. .
All docs
V22.1

End-to-End Tests with xUnit

  • 3 minutes to read

You can use the xUnit framework to create and run functional tests for XAF applications.

Step 1—Add the Selenium Driver to Your System

Tip

You can skip this step if you test only WinForms XAF applications.

XAF exposes the API that allows you to use the Selenium driver to interact with browser and individual web page elements.

To run functional tests for ASP.NET Web Forms and ASP.NET Core Blazor XAF Applications, install browser drivers.

Selenium requires a path to the downloaded driver. Add a folder with the driver to the system’s PATH variable.

Step 2—Add a Test Project

Right click the solution and select Add DevExpress Item | New Project…. In the DevExpress Template gallery, select .NET Core, XAF Solution Wizard (.NET Core) and click Run Wizard.

easytest add test project template gallery

The XAF Solution Wizard opens. Select End-to-End Testing Project, specify the project name and click Finish.

easytest add test project

Add a test project manually

Add a new “xUnit Test Project” project to your solution.

In the project file, change the following:

<PropertyGroup>
  <!-- Set a target framework for Blazor -->
  <TargetFramework>net6.0</TargetFramework>


  <!-- Set a target framework for .NET6+ Desktop (and Blazor)  -->
  <TargetFramework>net6.0-windows</TargetFramework>
  <UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>

Add EasyTest references.

<ItemGroup>    
    <!-- .NET 6+ WinForms-->
    <Reference Include="DevExpress.EasyTest.v22.1">
      <HintPath>..\..\..\Bin\NETCore\DevExpress.EasyTest.v22.1.dll</HintPath>
    </Reference>
    <Reference Include="DevExpress.ExpressApp.EasyTest.WinAdapter.v22.1">
      <HintPath>..\..\..\Bin\NETCoreDesktop\DevExpress.ExpressApp.EasyTest.WinAdapter.v22.1.dll</HintPath>
    </Reference>
    <Reference Include="DevExpress.ExpressApp.EasyTest.BlazorAdapter.v22.1">
      <HintPath>..\..\..\Bin\NETCore\DevExpress.ExpressApp.EasyTest.BlazorAdapter.v22.1.dll</HintPath>
    </Reference>

</ItemGroup>

Configure end-to-end tests.

public class MainDemoFixture : BaseFixture {
    protected const string BlazorAppName = "MainDemoBlazor";
    protected const string OnlineBlazorDemo = "OnlineBlazorDemo";
    protected const string WinAppName = "MainDemoWin";
    protected const string MainDemoDBName = "MainDemo";
    public MainDemoFixture(ITestOutputHelper output) : base(output) {
        FixtureContext.RegisterApplications(
            new BlazorApplicationOptions(BlazorAppName, @$"{XafPath}\Demos\CS\MainDemo\MainDemo.Blazor.ServerSide"),
            new BlazorApplicationOptions(OnlineBlazorDemo, string.Empty, url: @"https://demos.devexpress.com/xaf/blazordemo"),
            new WinApplicationOptions(WinAppName, @$"{XafPath}\Demos\CS\MainDemo\MainDemo.Win\bin\EasyTest\MainDemo.Win.exe")
        );
        FixtureContext.RegisterDataBases(new DataBaseOptions(MainDemoDBName, "MainDemo_v22.1", DataBaseType.MSSQL, server: "(localdb)\\mssqllocaldb"));
    }
}

Tip

The Solution Wizard can create a new solution that already have integrated a functional test project.

easy test create test project

Step 3—Create a Test

Add test code.

[Theory]
[InlineData(BlazorAppName)]
[InlineData(OnlineBlazorDemo)]
[InlineData(WinAppName)]
public void MainDemo_CreateTask(string applicationName) {
        FixtureContext.DropDB(MainDemoDBName);
        var appContext = FixtureContext.CreateApplicationContext(applicationName);
        appContext.RunApplication();
        appContext.GetForm().FillForm(("User Name", "Sam"));
        appContext.GetAction("Log In").Execute();
        appContext.Navigate("Tasks");
        appContext.GetAction("New").Execute();
        appContext.GetForm().FillForm(
            ("Subject", "Prepare financial statements for presentation to boards of directors"),
            ("Priority", "Normal"),
            ("Start Date", "1/11/2006"),
            ("Due Date", "1/12/2006")
        );
        appContext.GetAction("Save").Execute();
        Assert.Equal(
            new string[] { "Prepare financial statements for presentation to boards of directors", "Normal", "1/11/2006", "1/12/2006" },
            appContext.GetForm().GetPropertyValues("Subject", "Priority", "Start Date", "Due Date"));
}

Run Tests

  1. Switch the solution configuration to EasyTest.

  2. Right-click the solution and select Run Tests.