Skip to content

Use Cases

Steve Gilham edited this page Jul 23, 2018 · 5 revisions

Contents

Use Case : Unit tests (Framework or Mono)

In the case of a single unit test assembly, then executing AltCover with /i=<unit test output directory> to pick up the tests and dependencies, with a strongname replacement /sn=<my component key> will usually be sufficient, as framework assemblies without symbols will be ignored. The test execution can then happen in the context of the output directory.

If there are symbol-bearing third-party assemblies (e.g. from NuGet packages such as Mono.Options.Signed as in this project), then those can be excluded with an extra /s=<identifying substring of third party name>

Use Case : Unit tests (.net core)

The simplest approach is the dotnet test integration.

If more customisation is required, then any of the dotnet focussed Examples of Use indicate how this can be achieved.

Use Case : Windows Service

The simplest case involves patching the service under test. The service should be installed and working on the test machine, with the symbols co-located with the assemblies of interest. Stop the service, run AltCover on the directory containing the service, swap that folder and the one with the AltCover output (ensuring that the coverage file is not moved in this operation and is writeable by the service), then restart the service and begin testing.

When the test is complete, stop the service, swap the uninstrumented binaries back into place so that service operations won't continue to write to the coverage file, and use the coverage data as desired.

See the instructions under Demo/Service for a worked example

Alternatively, the binaries could be instrumented as a build step, and included, along with the coverage XML file and the AltCover.Recorder.g.dll helper, in an installer. The coverage XML file would in that case need to be installed to the exact same file path as it was created in on the build machine.

AltCover can be used in runner mode with services, by for example launching a script to start the service, perform whatever tests and then stop the service.

Use Case : Web Application

Most of the notes for a Windows Service apply here for system/integration testing; the important part is that the IIS application must be gracefully shut down to flush the coverage to disk.

For testing in the Visual Studio environment, the explicit "Instrument now, test later, collect coverage after that" mode of operations is appropriate. Begin with

altcover --save --inplace -i $(OutputDir)

to instrument the code where it will be launched by pressing F5; then execute whatever test cases required and shut the site down through the system tray widget to achieve a graceful shutdown. Then the coverage data can be collected via

altcover runner --collect -r $(OutputDir)

In deployment tests, the process remains the same, only with $(OutputDir) being replaced by the location of the deployed code. In addition, coverage can be gathered without having to stop the server by use of the pause and resume feature introduced in release 3.0.466