Flexible application of pile functions in white box testing

Source: Internet
Author: User

Flexible application of pile functions in white box testing

Author: Zhang yuanli

Http://blog.csdn.net/vincetest

First, we can understand what is a pile function. The following is a definition. For more information, see the white box test article.

Test Pile: replaces the entity of the submodule called by the tested module. This entity is generally a pile function. This test pile is what we call the pile function,

So a good function, why do we have to replace the whole pile function? Isn't that okay? When it comes to ideas, this is the application that I want to tell you about.

For example, the following code is tested ):

// Tested source code // called function int callfunc () {return 88;} int myfunc () {If (callfunc ()> 10) {return 1 ;} else {return 0 ;}}

I. troubleshooting: Problems found during myfunc () testing, but we cannot determine whether callfunc () is the cause. We use the pile function to replace callfunc (), the pile function and callfunc () the functions are completely consistent, so we must ensure that the pile function is 100% correct, so that we can eliminate the problem of callfunc () or myfunc.

Ii. complete replacement: The function called in the function under test is not implemented due to progress or other reasons. In order to test and simulate a function to replace the function to ensure normal operation of the test, especially in agile and fast iterative development models, it should appear frequently. For example, callfunc () is an empty function that does not implement any function at all. To test myfunc (), we must simulate a pile function to achieve the purpose of testing.

Iii. Specific Purpose: To replace the original functions for a specific purpose, such as forcing changes to the test branch and simplifying complex services, rather than actually constructing a lot of business environments to meet the conditions, to save money, use a simple and practical method for direct substitution. For example, in callfunc (), 88 is usually returned, and less than 10 is returned under extremely harsh conditions, it is very difficult to construct this case. However, to test the else branch in myfunc (), we only need to force the return value of callfunc () to be less than 10. Example:

# Test code # define a pile function func stub_func (VC): Print ("in stub_func"); Return 8end; # Write back the callfunc function VD. callfunc. stub (Global. stub_func); # Call the tested function VD during piling. myfunc (); # Delete the pile VD. callfunc. stub (NiL );

White-box testing Article white-box Testing Technology
Welcome to repost this article, reprinted please indicate the source of the article: Zhang yuanli's blog http://blog.csdn.net/vincetest

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.