Telerik blogs
DotNetT2 Dark_1200x303

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:

Sample JustMock test project

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:

Sample pipeline with JustMock v2 task

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.

  1. Add (or update) the JustMock.Commercial R3 2020 (2020.3.916.1) NuGet package reference in the test project. Here is the sample:
    <ItemGroup>
        <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" />
    </ItemGroup>
  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:

    Feeds and authentication
    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'
      inputs:
        restoreSolution: '$(Parameters.solution)'
        feedsToUse: config
        nugetConfigPath: nuget.config
        externalFeedCredentials: 'Telerik NuGet Repo'  
  3. 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:
    JustMock profiler paths
    The YAML task looks as following:
    - task: vs-publisher-443.jm-vstest-2.JustMockVSTest-2.JustMockVSTest@2
          displayName: 'VsTest - testAssemblies'
          inputs:
            pathTo64BitJustMockProfiler: '$(UserProfile)\.nuget\packages\justmock.commercial\2020.3.916.1\runtimes\win-x64\native\Telerik.CodeWeaver.Profiler.dll'
            pathTo32BitJustMockProfiler: '$(UserProfile)\.nuget\packages\justmock.commercial\2020.3.916.1\runtimes\win-x86\native\Telerik.CodeWeaver.Profiler.dll'
  4. Now we are ready to run the pipeline.

    Pipeline execution

All done, happy mocking!


Ivo Stoilov
About the Author

Ivo Stoilov

Ivo Stoilov is a senior software engineer at Progress. He has 20+ years of experience with diverse technologies in variant roles. Outside of work, Ivo loves outdoor activities and exploring new places.

Related Posts

Comments

Comments are disabled in preview mode.