Skip to main content
All docs
V24.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. There are two ways to create such tests in XAF applications: with the Wizard (recommended) or manually. The following sections describe each option in more detail.

Step 1—Add the Selenium Driver to Your System

Tip

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

XAF exposes 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 that driver to the system’s PATH variable.

Step 2—Create a Test Project

Using the Wizard

  1. If your project is configured for .NET, build that project’s solution in advance.

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

    easytest add test project template gallery

  3. When the XAF Solution Wizard opens, select End-to-End Testing Project, specify the project name, and click Finish.

    easytest add test project

  4. A default test is generated for each platform.

Tip

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

easy test create test project

Manuall Test Project Creation

  1. Add a new xUnit Test Project project to your solution.

  2. 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>
    
  3. Add EasyTest references.

    <ItemGroup>
    <PackageReference Include="DevExpress.ExpressApp.EasyTest.BlazorAdapter" Version="24.1.7" />
    <PackageReference Include="DevExpress.ExpressApp.EasyTest.WinAdapter" Version="24.1.7" />
    </ItemGroup>
    
  4. Configure end-to-end tests. For this purpose, add a new Tests.cs file to your test project.

    using DevExpress.EasyTest.Framework;
    using Xunit;
    
    [assembly: CollectionBehavior(DisableTestParallelization = true)]
    
    namespace YourSolutionName.Module.E2E.Tests;
    
    public class YourSolutionNameTests : IDisposable {
        const string BlazorAppName = "YourSolutionNameBlazor";
        const string WinAppName = "YourSolutionNameWin";
        const string AppDBName = "YourSolutionName";
        EasyTestFixtureContext FixtureContext { get; } = new EasyTestFixtureContext();
    
        public YourSolutionNameTests() {
            FixtureContext.RegisterApplications(
                new BlazorApplicationOptions(BlazorAppName, string.Format(@"{0}\..\..\..\..\YourSolutionName.Blazor.Server", Environment.CurrentDirectory)),
                new WinApplicationOptions(WinAppName, string.Format(@"{0}\..\..\..\..\YourSolutionName.Win\bin\EasyTest\net6.0-windows\YourSolutionName.Win.exe", Environment.CurrentDirectory))
            );
            FixtureContext.RegisterDatabases(new DatabaseOptions(AppDBName, "YourSolutionNameEasyTest", server: @"(localdb)\mssqllocaldb"));               
        }
        public void Dispose() {
            FixtureContext.CloseRunningApplications();
        }
    }
    
  5. For .NET Framework 4.5.2+ projects, add a xunit.runner.json file to your test project.

    {
        "shadowCopy": false
    }
    

    In the xunit.runner.json file’s properties window, set the Build Action property to Content and the Copy to Output Directory to Copy if newer.

  6. Add test code to the Tests.cs file. For example:

    [Theory]
    [InlineData(BlazorAppName)]
    public void TestBlazorApp(string applicationName) {
        FixtureContext.DropDB(AppDBName);
        var appContext = FixtureContext.CreateApplicationContext(applicationName);
        appContext.RunApplication();
        appContext.GetForm().FillForm(("User Name", "Admin"));
        appContext.GetAction("Log In").Execute();
        Assert.True(appContext.Navigate("My Details"));
        Assert.True(appContext.Navigate("Role"));
        Assert.True(appContext.Navigate("Users"));
    }
    

Step 3—Run Tests

  1. Switch the solution configuration to EasyTest.
  2. Build the solution.
  3. Right-click the solution and select Run Tests.