How to quickly add a logging to a coded web test?

A coded web test, as opposed to a basic web test, brings more flexibility to the developer: conditioning, looping, code re-usage, etc. If you haven’t created one yet, you can follow an instruction on MSDN.

Now, because a coded web test can have some logic inside, it makes sense to add logging so that there’s a trace on what’s going on while it executes.

The easiest way to add a logging feature is to use AddCommentToResult method of WebTest class:

public class AWebTest : WebTest
{
    public override IEnumerator GetRequestEnumerator()
    {
        AddCommentToResult("This is a comment");

        // test code to go there
    }
}

When you open the test result you will see something similar to this:
webtestresult

Of course, this is not the most convenient and appropriate way of saving the trace of the test, but there are no additional steps needed to get it working. However, if you need only small amount of very basic information you can give it a try.

Previous Post
Next Post