lundi 10 octobre 2016

visual studio web test error handling

I'm using Visual Studio Ultimate 2013 and have a load test that uses a web test with a number of request and web test plugins.

In my PostRequest plugin, I'm checking the http status code of the response and am flagging an error in a WebTest.Context parameter, when a hhtp code of over 400 is returned. What I want to do is pick this up in the PostTransaction WebTest plugin and update a database table. The problem is, that the test aborts when the framework detects the error and the PostTransaction plugin isn't called.

I've added a PostWebTest plugin, that I thought would be called when the test iteration aborted, but it's never hitting this when a request fails. It does hit it if the test is successful. What am I missing?

public override void PostRequest(object sender, PostRequestEventArgs e)
{
    ...
    statusCode = e.Response.StatusCode.GetHashCode();
    If (statusCode > 400)
    {
        e.WebTest.Context["TransactionFailCount"] = 1;
    }
}

public override void PostTransaction(object sender, PostTransactionEventArgs e)
{
    int transactionFailCount = Convert.ToInt32(e.WebTest.Context["TransactionFailCount"]);
    if (transactionFailCount > 0)
        failCount = 1;
    else
        passCount = 1;
    ...
    base.PostTransaction(sender, e);

 }

 public override void PostWebTest(object sender, PostWebTestEventArgs e)
 {
     base.PostWebTest(sender, e);
 }

Thanks

Aucun commentaire:

Enregistrer un commentaire