I have revamped my TestFixture generator to work with the StatementGraph (i.e. FlowGraph). The generator logics has not changed:
- Build the Statement Graph from the method,
- Extract the path necessary to cover the entire graph (cover all statements in the method),
- Create one method for each path
- In each method documentation, output the decompiled code where the "target" statements have been highlighted.
Disclaimer
- This generator is far from behing finished or optimal: the algorithm to produce the graph is not optimal, I have not implement the Newyork Street Sweeper algorithm yet,
- If your code is buggy, the generator will generate tests for ... buggy code.
Examples
Here's a sample of what gets output from the examples in the StatementGraph article. Targetted statements are marked with /* i */ where i is the index of the tested statement
/// <summary>Test fixture for the <see cref="StatementSamples"/> class</summary>/// <remarks />[TestFixture()]
public class StatementSamplesTest{
/// <summary>Tests the Simple method</summary> /// <remarks> /// <para>Test coverage (estimated): 100,0%</para> /// <para>Target path:</para> /// <code>/* 0 */ Console.WriteLine("hello"); /// </code> /// </remarks> [Test()]
[Ignore("NotImplemented")]
public virtual void Simple0() {
} /// <summary>Tests the Block method</summary> /// <remarks> /// <para>Test coverage (estimated): 100,0%</para> /// <para>Target path:</para> /// <code>/* 0 */ Console.WriteLine("hello"); /// /* 1 */ Console.WriteLine("world"); /// </code> /// </remarks> [Test()]
[Ignore("NotImplemented")]
public virtual void Block0() {
} /// <summary>Tests the If method</summary> /// <remarks> /// <para>Test coverage (estimated): 83,3%</para> /// <para>Target path:</para> /// <code>/* 0 */ if (value < 0) /// { /// /* 1 */ Console.WriteLine("true"); /// /* 2 */ return; /// } /// Console.WriteLine("false"); /// </code> /// </remarks> [Test()]
[Ignore("NotImplemented")]
public virtual void If0() {
} /// <summary>Tests the If method</summary> /// <remarks> /// <para>Test coverage (estimated): 50,0%</para> /// <para>Target path:</para> /// <code>/* 0 */ if (value < 0) /// { /// Console.WriteLine("true"); /// return; /// } /// /* 1 */ Console.WriteLine("false"); /// </code> /// </remarks> [Test()]
[Ignore("NotImplemented")]
public virtual void If1() {
} /// <summary>Tests the While method</summary> /// <remarks> /// <para>Test coverage (estimated): 100,0%</para> /// <para>Target path:</para> /// <code>/* 0 */ int num1 = 0; /// while ((num1 < 10)) /// { /// /* 1 */ Console.Write(num1++); /// } /// </code> /// </remarks> [Test()]
[Ignore("NotImplemented")]
public virtual void While0() {
}}