New resources available on Microsoft Learn
Did you know that Microsoft Learn offers free training modules to assist you on your path to mastering Dynamics 365 for Finance and Operations? Become an expert at your own pace or share with your team to foster growth.
Dynamics 365 2019 release wave 2 plan Discover the latest updates to Dynamics 365.Release Plan | Weekly Deployment Notes
Ace your Dynamics 365 deployment with packaged services delivered by expert consultants.Explore service offerings
Connect with the ISV success team on the latest roadmap, developer tool for AppSource certification, and ISV community engagements.
ISV self-service portal
The FastTrack program is designed to help you accelerate your Dynamics 365 deployment with confidence.
FastTrack Program | Finance and Operations TechTalks | Customer Engagement TechTalks | Talent TechTalks
There is documentation from Microsoft online which says the SysTest framework supports role-based testing. I have scoured the internet but can't seem to find anyone who has utilised this feature.
If anyone could point me in the right direction to any information, or let me know the feasibility of such tests then that would be much appreciated.
For anyone who runs in to a similar issue in the future, the one bit of documentation I found to be useful on the matter is located at blogs.msdn.microsoft.com/.../automated-testing-guidance-for-ax-7
The code provided on this article is useful but needs a bit of tweaking to get working. The useful bit is the SysTestSecurityAttribute section, let me know if you need any further info by commenting on this post or messaging me
I am very interested in this topic. I created a table and form with restricted access. I am attempting to run a test under specific security role contexts such that under the correct role context, the test would pass (allowed to edit the table), and under the incorrect role the test would fail. I've tried using SysTestSecurityAttribute and SysTestSecurityContext class but have not been able to get it working.
Any advice or further resources would be greatly appreciated.
Sorry for the delay in getting back to you. I had to give up access to the developer VM we were using for the proof of concept we were undertaking. The following code specifies two roles for the test to use:
[SysTestTargetAttribute(classStr(SysTestSecurityContext), UtilElementType::Class), SysTestSecurityAttribute(#PersonaSecRole, ['57df6343-4dd9-4dc0-8a6b-61e454b023e4', 'd6c1da0e-521b-4261-b1db-eb47c6c129f5', 'TestEssentialsRole'], true)]
If you define this at the class level you should be fine.
The roles are the hex numbers (custom roles appear like this in the AOT). I retrieved these roles by clicking Dynamics 365 -> Addins -> View related roles for all duties in Visual Studio.
I'm also trying to get something like this working, I have the following and I can't get it to fail regardless of the role I put into the SysTestSecurityAttribute:
[SysTestTargetAttribute(classStr(SysTestSecurityContext), UtilElementType::Class),SysTestSecurityAttribute('test', ['TMSLOGISTICSMANAGER'], true)]
class ProjTests extends SysTestCase
public void TestRoleAccess()
SecurityContext context = SecurityContext::constructFromEntryPoint(SecurableType::MenuItemDisplay, menuItemDisplayStr(VendTableListPage), '');
The above works as long as you do a build between running the the test suite, if you don't the last build's data is still being used. I'm going to leave it as it is a working code example but I don't need help anymore. Thanks for the initial post!
Business Applications communities