Your first X++ unit test with SysTest in D365 F&O
Write and run a first X++ unit test with SysTest in D365 F&O: SysTestCase class, assertions, data isolation, test model and build integration.
The short answer
An X++ unit test is a class extending SysTestCase, where each test method carries the SysTestMethodAttribute attribute and checks a result with assertions (assertEquals, assertTrue, assertFalse…). You put it in a dedicated test model whose name contains "Test", build, and the tests show up in Visual Studio's Test Explorer, where you run them.
By default, each test runs with AutoRollback isolation: all writes are rolled back at the end, no data persists.
Writing the test
Example adapted from Microsoft Learn (Fleet Management sample app), checking a field validation:
class FMUnitTestSample extends SysTestCase
{
[SysTestMethodAttribute]
public void testFMCarValidateField()
{
FMCarClass fmCar;
fmCar.NumberOfDoors = -1;
this.assertFalse(fmCar.validateField(fieldNum(FMCarClass, NumberOfDoors)));
fmCar.NumberOfDoors = 4;
this.assertTrue(fmCar.validateField(fieldNum(FMCarClass, NumberOfDoors)));
}
}The setup method lets you prepare data before each test. After saving and building, open Test > Test Explorer, select the test and run it.
Isolation, test model and build
The SysTestTransaction attribute picks the isolation: AutoRollback (default, best), LegacyRollback (tracks and deletes inserts; useful for testing user connections or concurrency), LegacyRollbackWithUpdateTracking (slowest), None (debugging only).
[SysTestTransaction(TestTransactionMode::LegacyRollback)]
class MyTestSample extends SysTestCaseCreate a separate test model and include "Test" in its name: the default build definition discovers test modules by that name. Two documented caveats: builds on Microsoft-hosted agents do not support running SysTest tests (no runtime); in the unified developer experience (UDE), test code must be deployed to the environment before it runs, and requires Application Foundation and Test Essentials. See UDE: what changes for an X++ developer.
Common mistakes
- Writing tests that rely on unprepared existing data: they pass or fail depending on the environment.
- Switching to None isolation and forgetting to switch back: tests leave data behind.
- Mixing test code and application code in the same model.
- Expecting pre/post handlers on a test method: they are not hookable by default (add [Hookable(true)] if needed).
- Relying on the hosted pipeline to run tests: it only compiles and packages.
Having it generated
Unit tests are part of what Skalp delivers with the code. Skalp AI writes the specification, generates the X++ code and unit tests, compiles with a best-practice check, then delivers a pull request to your Azure DevOps: nothing is merged without your technical architect's approval. See AI X++ development, the bigger picture in building X++ without a consultant in 2026, and the Basic, Pro and Max plans (1 credit, ≈ €400 on Basic, €200 on Pro, consumed only when the code is generated).
Sources
- Microsoft Learn, "Testing and validations", updated 29 Apr 2026, accessed 18 Oct 2026.
- Microsoft Learn, "Build automation that uses Microsoft-hosted agents and Azure Pipelines", updated 5 Mar 2026, accessed 18 Oct 2026.
- Microsoft Learn, "Unified developer experience - Frequently asked questions", updated 23 Jul 2026, accessed 18 Oct 2026.
Frequently asked questions
Do my tests leave data in the database?
Not with the default AutoRollback isolation, which rolls everything back with SQL save points. Only the None option leaves data.
Can SysTest tests run in a hosted Azure DevOps pipeline?
No: according to Microsoft Learn, builds on hosted agents are limited to compiling and packaging, with no SysTest tests or database synchronisation.
Why put "Test" in the model name?
The default build definition discovers test modules whose names contain that word.
Ready to transform your D365?
Join the CIOs who develop their D365 tickets in 2–4 h for 1 credit (≈ €400 on Basic, €200 on Pro).