Abort web test if an error occurs
Using the VS2010 Load Test feature with recorded web tests.
I am having problems with cascading errors on my recorded websites. That is, if one request fails, several other requests will also fail. This creates a lot of clutter in the logs as usually only the first error matters.
Is there a way to make the erroneous validation rule complete the web test at the point of failure and NOT run the rest of the requests?
(to be clear, I still want to continue the load test altogether, just stop this particular iteration of this particular test case)
Here's some sample code that demonstrates what I'm trying to do:
using System.ComponentModel;
using Microsoft.VisualStudio.TestTools.WebTesting;
namespace TestPlugInLibrary
{
[DisplayName("My Validation Plugin")]
[Description("Fails if the URL contains the string 'faq'.")]
public class MyValidationPlugin : ValidationRule
{
public override void Validate(object sender, ValidationEventArgs e)
{
if (e.Response.ResponseUri.AbsoluteUri.Contains("faq"))
{
e.IsValid = false;
// Want this to terminate the running test as well.
// Tried throwing an exception here, but that didn't do it.
}
else
{
e.IsValid = true;
}
}
}
}
source to share
Use Assert.Fail () . This will stop the test and throw an AssertFailedException just like any failed assertion.
if (e.Response.ResponseUri.AbsoluteUri.Contains("faq"))
{
e.IsValid = false;
Assert.Fail("The URL contains the string 'faq'.");
}
This will only stop the specific test. At the end of the load test, you can see that the total number of tests failed with this exception.
source to share