White box testing and black box testing (thanks to dongzige for answering)

Source: Internet
Author: User

Q: How can I perform white-box and black-box tests on this function? Are there any errors with this function?

 
//Tested InterfaceFloatAVG (Float* List,IntCount ){FloatSum =0.0;For(IntIndex =0; Index <count; index ++) Sum+ =List [Index];ReturnSum/Count ;}

A:

 

Float AVG (float * List, int count)
Black Box: Test Case
White Box: Code Review

 

Result of this white box:
1. No comments
2. The list is not empty.
3. The case where count is 0 or negative is not processed
4. pointer overflow not processed
5. Sum overflow is not processed (5 of the cases are estimated that the black box is not easy to test .)

 

Black box:
AVG (float *) null, 0 );
AVG (list, 0 );
AVG (list, 5 );
AVG (list, 10 );
AVG (list,-1); // The list length is 10

Dongzige: white box testing is actually based onCode. The code is too simple, but it is also written in the code... Otherwise, I cannot think of so many possibilities. As a matter of fact, it is better to set up the black box and review the code. When you have defined the functions of a function... How to implement it internally. We do not do white-box testing, only do black box and code review, and do not do unit testing like private methods. The existing test framework cannot test the private function.

Summary:

The so-called black box testing does not mean that you can not write test code, just pass the manual testing (I think our company's testing seems to have this knowledge ). The Black Box definition plans Input and Output based on predefined functions. For example, if the function specifies that input x must obtain y, then input x determines whether the output is Y. If input x is Y, the output is correct. If input x is not y, the output can be written in a test case, what is the difference between a white box and a black box? White box is to read the code first, organize the test cases and their input, letProgramThe Execution Branch is the same as what you want, and then the logic, branches, and boundaries of the edges and corners are covered. From the code snippets alone, there should be no difference, in addition, there are a large part of test cases. The white box and black box overlap, but the white box should have a lot more use cases than the black box, so the cost is actually higher than the black box, therefore, the strategy of companies and teams is to write only black boxes for testing without writing white boxes, and replace white boxes with code review.

 

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.