A quick guide to explain how to use the JustMock.Commercial package on Azure DevOps.
One of the main features of the JustMock.Commercial R3 2020 release is the possibility to deploy the JustMock profiler along with the mocking framework assemblies. This greatly improves the usability and fixes some of the drawbacks from previous versions. So far so good, but probably many of you would be curious about how this new feature can be used in Azure DevOps. With this post, I will try to give a short recipe in a few simple steps to make it work in your CI/CD pipeline.
For the purpose of the exercise we will use a minimal MSTest Unit Test project imported in the source repository:
The sample project is available on GitHub.
We also need a pipeline derived from the .NET Desktop task template. The initially generated VsTest task is replaced with JustMock Tests v2 task. Here it is:
Of course, the build definition above is just an example and you could continue to use your preferred approach for building pipelines, even with YAML.
Let us go through required configuration step by step.
- Add (or update) the JustMock.Commercial R3 2020 (2020.3.916.1) NuGet package reference in the test project. Here is the sample:
<PackageReference Include="JustMock.Commercial" Version="2020.3.916.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.1.2" />
<PackageReference Include="MSTest.TestFramework" Version="2.1.2" />
- The JustMock.Commercial package is available on the Telerik NuGet feed, so you need to configure feeds and authentication in NuGet restore task as following:
The detailed instructions for creating NuGet configuration file and configuring Service Connections on Azure DevOps are covered in another blog post, Azure DevOps and Telerik NuGet Packages.
Using YAML, the task configuration looks like this:
- task: NuGetCommand@2
displayName: 'NuGet restore'
externalFeedCredentials: 'Telerik NuGet Repo'
- The last, but important part of the configuration is to set the profiler paths for both 32- and 64-bit targets in the JustMock Test task to the corresponding locations in the local NuGet cache. By default these paths are placed in the user profile directory and contain the particular version of the package:
The YAML task looks as following:
- task: vs-publisher-443.jm-vstest-2.JustMockVSTest-2.JustMockVSTest@2
displayName: 'VsTest - testAssemblies'
Now we are ready to run the pipeline.
All done, happy mocking!