Create web test and verification rules by yourself

Source: Internet
Author: User
" Web TestingIs composed of a series of HTTP requests, by sending HTTP requests at the protocol layer WorkOf TestType. Vsts comes with several pre-defined verification rules, such as searching for certain characters on the returned page and whether the returned documents contain certain tags. A security filter was tested some time ago. The basic function of this filter is to filter some content that may constitute a security risk, such as the content of the <SCRIPT> tag and JS content. After the test is completed according to the pre-given test case, OK, no problem, but one problem found one hour after going online, that is, the content output through the security filter will be two characters more than the original content-"\ r \ n". This problem will be fixed in a moment, trim. Then I will add the regression test implementation for this problem to the original test. Unfortunately, the web test does not have a validation rule for the length of the returned content, MicrosoftProvides an interface for creating custom verification rules. We can create a rule for verifying contentlength.

1. Create a new class library project, which is an independent reusable class library. The created web test plug-in can be used in different projects that contain web tests. In fact, you can follow the previous articleArticleWebtest plugin shares a class library project.

2. Add a reference to "Microsoft. visualstudio. qualitytools. webtestframework" in this class library project.

3. Create a class derived from validationrule in this class library project.

4. Override the validate method of the base class

5. Open the WebTestAnd reference the class library project that you just added with custom verification rules.

6. Open the web test that needs to call a custom verification rule, click "add validation rule", and select the verification rule you just compiled.

Now let's take a look at adding parameters to the custom verification rules so that users can enter the corresponding parameters to make the verification rules more flexible.

Public class responsecontentlength: validationrule
{
Public int length {Get; set;} // input length
Public bool passifequalstocontentlength {Get; set ;}
 
Public override void validate (Object sender, validationeventargs E)
{
If (E. Response! = NULL)
{
E. isvalid =! (E. Response. contentlength = length) ^ passifequalstocontentlength );
}
If (! E. isvalid)
{
E. message = string. format ("the length of the contentlength: {0} is not equal to the expected result: {1 }. ", E. response. contentlength, length );
}
}
}

If we add this custom rule, we will be prompted to enter two parameters: length and Boolean. If the contentlength in response is equal to the configured length, if this Boolean value is set to true, the verification rule will pass.
From: http://www.51testing.com/html/42/n-130642.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.