I would like to enhance efficiency in our software department by providing a VS extension or add in to perform custom code coverage using VS 2013.
The special point in that enterprise is the coverage of special code snippet actually marked by a comment like //INDISPENSABLE_STUFF document comment
that is defined as a task token.
I was thinking of introducing a new attribute RiskAttribute
to qualify methods for instance but could not separate the corresponding code coverage result from the rest for reporting how much of the indispensable stuff has been covered.
/// <summary>
/// Risk Attribute
/// </summary>
public class RiskAttribute : Attribute
{
private readonly string _document;
private readonly string _comment;
/// <summary>
/// Constructor
/// </summary>
/// <param name="doc"></param>
/// <param name="comment"></param>
public RiskAttribute(string doc, string comment)
{
_document = doc;
_comment = comment;
}
/// <summary>
/// Document
/// </summary>
public string Document { get { return _document; } }
/// <summary>
/// Comment
/// </summary>
public string Comment { get { return _comment; } }
}
I turned to implement an add in but do not figure out in the 1. step how to launch the vs code coverage tool programmatically for a project using my add-in. The 2. step would be to customize the code coverage in order to parse the custom task token and return a result like xy% of defined task token INDISPENSABLE_STUFF is covered
.
For development, I implemented a calculator class with unit test to exercise both variations:
The class
/// <summary> /// Calculator /// </summary> public class Calculator { /// <summary> /// Addition /// INDISPENSABLE_STUFF (DOC #2150) Test /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static decimal Add(decimal a, decimal b) { return a + b; } /// <summary> /// Substraction /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> [RiskAttribute("DOC #2150", "Test")] public static decimal Sub(decimal a, decimal b) { return a - b; } }
The unit test
/// <summary> /// Test class for Calculator /// </summary> [TestClass] public class CalculatorTest { /// <summary> /// Tests addition /// </summary> [TestMethod] public void Test_Sub() { decimal a = 1; decimal b = 2; Assert.AreEqual((a - b), Calculator.Sub(a, b)); } }
So now, for the question, I already have to add-in code for the integration but miss the main content to start the customized code coverage. Does anybody know :
- how to adapt the code coverage to consider task token?
- how to start the code coverage programmatically?
Sorry if these are "big" points for only "one" question.
Thanks