This is the first part of Automated testing with Permissions, in this post I’ll visualize and explain the way it’s described on msdn and in part two I’ll go for a more practical approach which will support permissions per test function and partial execution of code with a permission set.
As a developer you’re responsible for writing automated tests, and every manual test you can automate should be automated, same goes for testing with permission sets.
In NAV 2017 Microsoft has introduced a way to do this, you can find all about it on msdn.
To make things a bit more clear I’ve created the image below:
So assigning permission set(s) should be done in the CAL Test Runner codeunit (130400) or by creating your own Test Runner.
Since the standard Test Runner does it’s job perfectly this is a bit odd but okay..
Each Test Codeunit and Test Function has it’s own TestPermissions property, you can either set it to Restrictive or NonRestrictive on Test Codeunit level or set it for each individual function.
The magic OnBeforeTestRun function is triggered for each test function, so that’s the place where you have to assign the desired permission set(s).
Your code will then look something like this:
Notice the global PermissionTestHelper variable, it’s a new dll added in NAV 2017.
The most important function is called AddEffectivePermissionSet, you can call this function multiple times to add effective permission sets.
Note: the Microsoft.Dynamics.Nav.PermissionTestHelper.dll is located in the server add-ins folder.
- Control permissions on a high level.
- To get started you have to modify the existing TestRunner or create your own.
This would be unnecessary if there was an event and the standard TestRunner is just fine!
- At some point you might want to assign permission sets on a test function level, this is not supported.
- The entire test is run with the effective permission set, this can be a problem in case you want to set up data and/or verify results in the function since this requires more permissions.