-
Notifications
You must be signed in to change notification settings - Fork 30
Getting Started GetCodeCoverageTotal activity
Click on the Arguments tab of your workflow and add an Int32 in argument called “CoverageFailureIfBelow”. Set the metadata as follows:
Now scroll down in the workflow until after the testing section, between “If CompilationStatus = Unknown” and “If TestingStatus = Uknown”. Add a Sequence between the two If activities called “Check Coverage”.
Click on Variables at the bottom of the workflow window and create an Int32 variable (scoped to Check Coverage, called coverageTotal). You can double-click the sequence to “zoom in”.
The “GetCoverageTotal” activity relies on the test attachments that the test engine uploads to TFS when the tests are completed (most notably the Code Coverage attachment). Since this is done asynchronously, I introduced a Delay activity. Add a new Argument to the workflow (if you don’t want to hard-code the delay) and set its default to 10 seconds.
Set the Timeout of the Delay activity to
Timespan.FromSeconds(arg)
where arg is the name of your timeout argument.
Drop a “GetCoverageTotal” activity (from the custom assembly) into the sequence (NOTE: You may have to import the assembly into the Toolbox if you’ve never done that before). Set the properties as follows:
Once that’s done, you now have the coverage total, so you can do whatever you need to. For example, put an "If" that evaluates if the total coverage is too low or not. If the coverage is too low, set the BuildDetail.TestStatus to TestStatus.Failed. You can also set the overall build status to PartiallySucceeded and have a WriteBuildWarning (“Failing build because coverage is too low”) or WriteBuildMessage (“Coverage is acceptable”) depending on the result.