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.
- For Google Chrome: download “chromedriver.exe” from https://chromedriver.chromium.org/downloads.
- For Microsoft Edge: download “msedgedriver.exe” from https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/?form=MA13LH.
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
If your project is configured for .NET, build that project’s solution in advance.
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 .
When the XAF Solution Wizard opens, select End-to-End Testing Project, specify the project name, and click Finish.
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.
Manuall Test Project Creation
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> <PackageReference Include="DevExpress.ExpressApp.EasyTest.BlazorAdapter" Version="24.1.7" /> <PackageReference Include="DevExpress.ExpressApp.EasyTest.WinAdapter" Version="24.1.7" /> </ItemGroup>
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(); } }
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 theBuild Action
property toContent
and theCopy to Output Directory
toCopy if newer
.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
- Switch the solution configuration to
EasyTest
. - Build the solution.
- Right-click the solution and select Run Tests.