Post by Chris Lowe |
In July 2017 Microsoft announced that type provider tests were to replace form adaptor tests as the mechanism to verify the integration between forms and the underlying code within Dynamics 365 for Finance and Operations (D365FO). The announcement outlines the reasons for the change, in that the form adaptors models were ‘expensive to run and maintain’. The new type providers in comparison provide ‘instant design time support, so that tests can access forms’ removing the need for the extra generate and compile time.
Martin Fowler is a leading author and speaker on software design and he terms these types of tests as ‘subcutaneous tests’ which operate just under the browser user interface. Within D365FO forms, they provide a way to write fast running automated tests which access the controls and trigger events to ensure your unit tested code integrates successfully. They simulate the behaviour of the user, but do not test directly through the user interface.
Searching the internet there is currently limited information and few examples covering how to set up and develop these type provider tests. In this first in a series of posts around type provider tests, we will go through the process we have used to set them up. Through the rest of the series we will take a look at writing type provider tests.
Creating the test model
Firstly we need to create a new model that is going to contain our type provider tests. This is done using the Model Management options that are located on the Dynamics 365 menu in Visual Studio. Selecting Model Management displays some further options. One of these options is Create model….
Selecting this option opens the Create model dialog. The create model process is a straight forward four step wizard which defines how your model will be set up. The first step is to enter the model name and other properties. Complete the fields on the Add parameters page and click the Next button.
The second stage of the wizard called Select package will be displayed. In this step you need to select whether the model will be based on an existing package and used to create overlays, or whether you would like to create a new package to extend the application. As you are writing tests, you will create this model as a new package. Select the Create new package option and click the Next button.
The Select referenced packages page will be displayed as the third page, allowing you to select the other packages that the model needs to reference. For the type provider tests some of the key classes are contained in the TestEssentials package. This model should be selected. Alongside this the ApplicationFoundation package should be selected as it is required for the unit test framework classes. ApplicationPlatform is already selected and should be left selected. You will also need to select the ApplicationSuite package as this will be required when you start to write tests in the next post. You should also select any packages that contain the form and elements that you will be testing. Select the required packages and click the Next button.
The Summary page will be displayed as the final step in the wizard, reviewing what has been selected in the previous steps. It’s useful to select the Create new project option as it will set up a project where you can complete the remaining setup steps and start creating type provider tests. Click the Next button.
If you ticked the Create new project check box, you will be presented with the standard Visual Studio create solution/project dialog as per the screenshot below. Enter the required project Name, select the Location of the files and specify a Solution name. Click the OK button for the solution/project to be created and opened in Visual Studio.
You have successfully created our test model that will contain our type provider tests. You now need to add a Visual Studio project reference to the type provider assembly. This assembly is called Microsoft.Dynamics.Ax.TypeProviders.FormAdaptors.dll, and it is located on your development environment in the
AosService\PackagesLocalDirectory\Bin folder. The AosService previously was located on the J drive, but in recent updates to the development environments it can also be found on the K drive.
On my development environment the full path to the assembly is:
The next step is to add this assembly as a reference to test model project. However, from investigations we have found that adding the reference directly to the assembly in the
AosService\PackagesLocalDirectory\Bin folder causes a number of errors when you build the project. The compilation complains about missing assemblies. Trying to copy the additional assemblies to the
AosService\PackagesLocalDirectory\Bin folder leads to the compilation raising an error for a different missing assembly. To resolve this issue, the Microsoft.Dynamics.Ax.TypeProviders.FormAdaptors.dll assembly was copied to the bin folder of our newly created test model. In our example the location of this is:
Please note the bin folder will not be created until you have built your model for the first time. So build your new test model from the Dynamics 365 menu option in Visual Studio. Then copy the Microsoft.Dynamics.Ax.TypeProviders.FormAdaptors.dll assembly from
K:\AosService\PackagesLocalDirectory\Bin to the bin folder of the model i.e.
This will ensure that the assembly will be able to reference the other required assemblies.
The final step, back in Visual Studio is to add the project reference to the Microsoft.Dynamics.Ax.TypeProviders.FormAdaptors.dll assembly. In Visual Studio right click the References option in you newly created project. A submenu will be displayed. Select the option to Add Reference….
In the Add Reference dialog, click the Browse tab and navigate to the bin folder of your model (
K:\AosService\PackagesLocalDirectory\TypeProviderTestExamples\bin) and select Microsoft.Dynamics.Ax.TypeProviders.FormAdaptors.dll. Click the OK button.
Build your solution/project in Visual Studio. It should build successfully. You have successfully completed the setup for the type provider tests. In the next post you will learn how to write a type provider test.