Unit Test Partitions MsDyn365FO

In this post I want to talk about unit test partitions Microsoft Dynamics 365 for Finance and Operation.

Unit test partitions are the rest of a feature called data partitioning which was introduced in Microsoft Dynamics AX 2012 R2. In MsDyn365FO this this feature is listed as removed or deprecated features.

Behind the scenes data partitioning is still in use during execution of unit tests. There are several possible setups and ways on how to define the scope of an unit test partition e. g. per test case or per test method. We decided to use a customized process to create only one unit test partition per unit test run. The reason behind the decision is, that in our case the setup of a new unit test partition takes several minutes because we are creating everything from scratch. To implement this process we had to save the id of the successful created partition in a custom table and inject the same in the execution of each test case. If you are interested in more details, feel free to reach out to me.

At some point during debugging unit tests you will have to login to the created/used unit test partition e.g. to validate the setup via the UI. To do so you can check the existing partitions in table SysTestPartition or check the partition field in the “Autos” window while debugging. When you have identified the right partition id you can use the URL parameter “prt” to access it via UI. The following is an example on how to login to partition UT72: https://usnconeboxax1aos.cloud.onebox.dynamics.com/?cmp=DAT&prt=UT72

Another tricky thing while debugging unit tests is the database snapshot isolation of each test case. The good thing is that no test case is able to destroy the initial setup, but the bad thing is that you will not be able to see the modified/created data of a test case when you login via UI. To get around this limitation you can simply use the visual studio debugger. You can create a main method which instantiates the test case and calls the methods you want to call in this main method. In addition to that you have to set the unit test partition in the project properties for debugging and also manually select the test case as startup object. When you now start the debugger there will be no transaction isolation and you are able to debug also via UI.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s