altcover

This is the command-line usage

The full command line is

AltCover [/i[nputDirectory]=VALUE] [/o[utputDirectory]=VALUE] [/y|symbolDirectory=VALUE] [/d[ependency]=VALUE] [/k[ey]=VALUE] [/sn|strongNameKey=VALUE] [/r[eport]=VALUE] [/f[ileFilter]=VALUE] [/p[athFilter]=VALUE] [/s|assemblyFilter=VALUE] [/e|assemblyExcludeFilter=VALUE] [/t[ypeFilter]=VALUE] [/m[ethodFilter]=VALUE] [/a[ttributeFilter]=VALUE] [/attributetoplevel=VALUE] [/typetoplevel=VALUE] [/methodtoplevel=VALUE] [--l[ocalSource]] [/c[allContext]=VALUE] [/reportFormat=VALUE] [--inplace] [--save] [--zipfile] [--methodpoint] [--single] [--linecover] [--branchcover] [--dropReturnCode] [--sourcelink] [--defer] [--v[isibleBranches]] [/showstatic[=VALUE]] [--showGenerated] [--trivia] [--portable] [-q] [--verbose] [--?|help|h] [-- ] [...]
or
AltCover Runner [/r[ecorderDirectory]=VALUE] [/w[orkingDirectory]=VALUE] [/x|executable=VALUE] [--collect] [/l[covReport]=VALUE] [/t[hreshold]=VALUE] [/c[obertura]=VALUE] [/o[utputFile]=VALUE] [--dropReturnCode] [/summary|teamcity[=VALUE]] [-q] [--verbose] [--?|help|h] [-- ] [...]
or
AltCover ImportModule
or
AltCover Version
or, for the global tool only
AltCover TargetsPath

In detail

  -i, --inputDirectory=VALUE Optional, multiple: A folder containing assemblies
                               to instrument (default: current directory)
  -o, --outputDirectory=VALUE
                             Optional, multiple: A folder to receive the
                               instrumented assemblies and their companions (
                               default: sub-folder '__Instrumented' of the
                               current directory; or '__Saved' if '--inplace'
                               is set).
                               See also '--inplace'
  -y, --symbolDirectory=VALUE
                             Optional, multiple: Additional directory to search
                               for matching symbols for the assemblies in the
                               input directory
  -d, --dependency=VALUE     Optional, multiple: assembly path to resolve
                               missing reference.
  -k, --key=VALUE            Optional, multiple: any other strong-name key to
                               use
      --sn, --strongNameKey=VALUE
                             Optional: The default strong naming key to apply
                               to instrumented assemblies (default: None)
  -r, --report=VALUE         Optional: The output report template file (default:
                                'coverage.xml' or 'coverage.json' in the
                               current directory)
  -f, --fileFilter=VALUE     Optional, multiple: source file name to exclude
                               from instrumentation
  -p, --pathFilter=VALUE     Optional, multiple: source file path to exclude
                               from instrumentation
  -s, --assemblyFilter=VALUE Optional, multiple: assembly name to exclude from
                               instrumentation
  -e, --assemblyExcludeFilter=VALUE
                             Optional, multiple: assembly which links other
                               instrumented assemblies but for which internal
                               details may be excluded
  -t, --typeFilter=VALUE     Optional, multiple: type name to exclude from
                               instrumentation
  -m, --methodFilter=VALUE   Optional, multiple: method name to exclude from
                               instrumentation
  -a, --attributeFilter=VALUE
                             Optional, multiple: attribute name to exclude from
                               instrumentation
      --attributetoplevel=VALUE
                             Optional, multiple: Types marked with an attribute
                               of a type that matches the regex are considered
                               top-level, and are not excluded from coverage on
                               the basis of any type which textually encloses
                               them.
      --typetoplevel=VALUE   Optional, multiple: Types with a name that matches
                               the regex are considered top-level, and are not
                               excluded from coverage on the basis of any type
                               which textually encloses them.
      --methodtoplevel=VALUE Optional, multiple: Methods with a name that
                               matches the regex are considered top-level, and
                               are not excluded from coverage on the basis of
                               any method which textually encloses them.
  -l, --localSource          Optional: Don't instrument code for which the
                               source file is not present.
  -c, --callContext=VALUE    Optional, multiple: Tracking either times of
                               visits in ticks or designated method calls
                               leading to the visits.
                                   A single digit 0-7 gives the number of
                               decimal places of seconds to report; everything
                               else is at the mercy of the system clock
                               information available through DateTime.UtcNow
                                   A string in brackets "[]" is interpreted as
                               an attribute type name (the trailing "Attribute"
                               is optional), so [Test] or [TestAttribute] will
                               match; if the name contains one or more ".",
                               then it will be matched against the full name of
                               the attribute type.
                                   Other strings are interpreted as method
                               names (fully qualified if the string contains
                               any "." characters).
      --reportFormat=VALUE   Optional: Generate the report in the specified
                               format (Json, NCover or the default OpenCover)
      --inplace              Optional: Instrument the inputDirectory, rather
                               than the outputDirectory (e.g. for dotnet test)
      --save                 Optional: Write raw coverage data to file for
                               later processing
      --zipfile              Optional: Emit the coverage report inside a zip
                               archive.
      --methodpoint          Optional: record only whether a method has been
                               visited or not.  Overrides the --linecover and --
                               branchcover options.
      --single               Optional: only record the first hit at any
                               location, or first hit for each context if --
                               callContext is operating.
      --linecover            Optional: Do not record branch coverage.  Ignored
                               for the --reportFormat=NCover option.
                                   Incompatible with --branchcover.
      --branchcover          Optional: Do not record line coverage.  Ignored
                               for the --reportFormat=NCover option.
                                   Incompatible with --linecover.
      --dropReturnCode       Optional: Do not report any non-zero return code
                               from a launched process.
      --sourcelink           Optional: Display sourcelink URLs rather than file
                               paths if present.
      --defer                Optional, defers writing runner-mode coverage data
                               until process exit.
  -v, --visibleBranches      Optional: Hide complex internal IL branching
                               implementation details in switch/match
                               constructs, and just show what the source level
                               logic implies.
      --showstatic[=VALUE]   Optional: Instrument and show code that is by
                               default skipped as trivial.  --showstatic:- is
                               equivalent to omitting the parameter; --
                               showstatic or --showstatic:+ sets the unvisited
                               count to a negative value interpreted by the
                               visualizer (but treated as zero by
                               ReportGenerator) ; --showstatic:++ sets the
                               unvisited count to zero.
      --showGenerated        Optional: Mark generated code with a visit count
                               of -2 (Automatic) for the Visualizer if unvisited
      --trivia               Optional: Omit trivial sequence points
      --portable             Optional: portable operations - coverage report,
                               control file and recorded data co-located with
                               the recorder assembly
  -q                         Optional, multiple: Quiet mode -- once to switch
                               off informational messages, twice to switch off
                               warnings as well, three (or more) times to
                               switch off all messages.
      --verbose              Optional, multiple: Verbose mode -- once to switch
                               on detailed messages (or undo one level of -q if
                               any have been set)
  -?, --help, -h             Prints out the options.
-- ...                 Anything on the command line after a free-standing "--" is considered a separate command line to be executed after the instrumentation has been done.

or

  Runner
  -r, --recorderDirectory=VALUE
                             The folder containing the instrumented code to
                               monitor (including the AltCover.Recorder.g.dll
                               generated by previous a use of the .net core
                               AltCover).
  -w, --workingDirectory=VALUE
                             Optional: The working directory for the
                               application launch
  -x, --executable=VALUE     The executable to run e.g. dotnet
      --collect              Optional: Process previously saved raw coverage
                               data, rather than launching a process.
  -l, --lcovReport=VALUE     Optional: File for lcov format version of the
                               collected data
  -t, --threshold=VALUE      Optional: one or more of minimum acceptable
                               statement (S), branch (B) or method (M/AM)
                               coverage percentage (integer, 1 to 100) or
                               maximum acceptable CRAP score (C/AC followed by
                               integer, 1 to 255) e.g. M80C40B50. If the value
                               starts with a number, a leading S is assumed. If
                               any threshold is specified more than once, the
                               last instance is assumed -- so 25S50 counts as
                               S50.
                               Zero/absent values are ignored. If a coverage
                               result is below threshold, or the CRAP score is
                               above threshold, the return code of the process
                               is the largest abs(threshold - actual) rounded
                               up to the nearest integer. AM, AC include
                               methods with no source; the default is to ignore
                               such methods.
  -c, --cobertura=VALUE      Optional: File for Cobertura format version of the
                               collected data
  -o, --outputFile=VALUE     Optional: write the recorded coverage to this file
                               rather than overwriting the original report file.
      --dropReturnCode       Optional: Do not report any non-zero return code
                               from a launched process.
      --summary, --teamcity[=VALUE]
                             Optional: Defines the format of any summary; an
                               optional string value consisting of the tokens :
                               
                               'N' = No summary at all, regardless of other
                               values
                               'B' = TeamCity format, with branches as Block
                               items
                               'R' = TeamCity format, with branches as bRanch
                               items
                               'O' = Classic OpenCover format
                               'C' = Change Risk Anti-Pattern score
                               '+' is the same as "OC" (special case - "+" by
                               itself is the same as 'BOC')
                               If the option is present, but has no value, this
                               is the same as 'B'
                               If the option is not present, then the default
                               is 'OC'.
  -q                         Optional, multiple: Quiet mode -- once to switch
                               off informational messages, twice to switch off
                               warnings as well, three (or more) times to
                               switch off all messages.
      --verbose              Optional, multiple: Verbose mode -- once to switch
                               on detailed messages (or undo one level of -q if
                               any have been set)
  -?, --help, -h             Prints out the options.
-- ...                 Anything on the command line after a free-standing "--" is considered arguments for the executable to run.

or

  ImportModule               Prints out the PowerShell script to import the associated PowerShell module

or

  Version                    Prints out the AltCover build version

or, for the global tool only

  TargetsPath                Prints out the path to the 'altcover.global.targets' file
                               (as the tool cannot be 'dotnet add'ed to the project).
                               The 'altcover.global.props' file is present in the same directory

Notes

-e vs -s : what gives?

In the case where you have Unit Tests => Code Under Test => Libraries, and the coverage of the unit tests is not of interest, then exclude those assemblies with -e, so their dependencies get rewritten, but their contents are not instrumented or added to the coverage file. The stable libraries consumed by the code under test (and stable libraries for the unit test framework) should be marked as -s to be left untouched.

-p vs -f : what gives?

The distinction is that a single -p can exclude a folder $(SolutionRoot)Generated (though it has to be specified with manual expansion of the MSBuild variable) and everything in it, while a single -f can be used to exclude all .g.cs files wherever they are.

Runner mode : what gives?

There are three stages to the coverage operation – instrumenting the code, exercising it, then presenting the results. Classic altcover does the first, and as part of the process, injects the result presentation code into the system under test, to be run when the test process exits (as an exit handler).

This essentially doesn’t work with dotnet test in .net core (the exit handler doesn’t have enough time to work), so the runner mode was introduced to wrap the test processing, catching coverage data as it was generated, through a named pipe connection, and then doing the presentation work after the tests completed (release 1.5). The named pipe implementation proved unreliable as a cross-platform mechanism, so a file-based mechanism was adopted instead (release 1.6) that does work reliably in all places.

With the data being buffered to disk, rather than being stored entirely in memory in one or other process, the --save and runner --collect options were introduced (release 3.0) to do, respectively, the signalling to the system under test that it should dump live to an intermediate file, and the translation of the intermediate information into the final report, with the testing to be done at some point between, rather than having to run the tests through altcover runner.

In release 5.3, the writing the collected data has been offloaded to an in-process data handler, which removes this constraint; the data collector is automatically hooked into the MSBuild process.