Unit Tests and VSTS. How to configure team services build with different testing frameworks.
Configuring build just to check if code is compiling - it's boring and obvious, just create build, choose repository and add build solution task. That's it. This kind of build is useful for checking code integrity eg. after automatic merge. But it's much better to have also unit tests and run them, you can be more or less sure that when tests are green then the merge didn't broke anything vital.
I prepared solution with very simple class and method that can be tested. The method adds to numbers. The class is in class library so it cannot be run by itself.
Additionally I created number of projects with different unit tests frameworks. To show the most basic test definitions. There are may unit testing frameworks because they act differently in build.
MsBuild and NUnit 2.6 doesn't need any additional build configuration, but no one wants to use them any more. NUnit 3 and xUnit on the contrary, those frameworks needs adapters/runners.
Adapter/runner corresponding to unit test framework must be included in solution as a NuGet package. This provides the binaries that will enable run tests with default Visual Studio test runner. You don't have to include adapter in every test project, it is important to get the package that can be reused. For xUnit the package is xunit.runner.visualstudio and for NUnit it's NUnitTestAdapter.
Adapter/runner corresponding to unit test framework must be included in solution as a NuGet package. This provides the binaries that will enable run tests with default Visual Studio test runner. You don't have to include adapter in every test project, it is important to get the package that can be reused. For xUnit the package is xunit.runner.visualstudio and for NUnit it's NUnitTestAdapter.
Solution you can get from GitHub or just watch short intro:
Now lets create a build definition. Ready build definition you can get here. You can download this definition end import it in your Vsts. I'm using old Vsts look because it's more brief and presents more data on one screenshot.
For MsTest and NUnit 2.6 no additional configuration is required.
For NUnit 3 and xUnit there are already adapters in the solution so they will be restored to NuGet packages folder. Packages are restored into **\packages.
I'm using git so the final location is $(Build.Repository.LocalPath)\packages.
And this information must be presented to "Path to Custom Test Adapters" option of test task so the build can locate runners and use them.
For NUnit 3 and xUnit there are already adapters in the solution so they will be restored to NuGet packages folder. Packages are restored into **\packages.
I'm using git so the final location is $(Build.Repository.LocalPath)\packages.
And this information must be presented to "Path to Custom Test Adapters" option of test task so the build can locate runners and use them.