Black box vs White box Testing

2019-01-10 01:22发布

Which type of testing would you say should be the emphasis (for testers/QAs), and why?

A quick set of definitions from wikipedia:

Black box testing

  • takes an external perspective of the test object to derive test cases. These tests can be functional or non-functional, though usually functional. The test designer selects valid and invalid input and determines the correct output. There is no knowledge of the test object's internal structure.

White box testing

  • uses an internal perspective of the system to design test cases based on internal structure. It requires programming skills to identify all paths through the software. The tester chooses test case inputs to exercise paths through the code and determines the appropriate outputs. In electrical hardware testing, every node in a circuit may be probed and measured; an example is in-circuit testing (ICT).

edit: just to clarify a bit more, I realize that both are important, but usually they are separate between dev and QA.

Is internal knowledge important for the tester/QA? I've heard arguments that testing with this knowledge in mind enables them to better test for problems, but I've also heard arguments that this knowledge can distract from functional needs and promote "testing to to the code" rather than to the intended solution.

16条回答
forever°为你锁心
2楼-- · 2019-01-10 02:12

"Both" has been stated above, and is the obvious answer...but IMO, white box testing goes far beyond developer unit testing (althoughI suppose it could depend on where you draw the line between white and black). For example, code coverage analysis is a common white box approach - i.e. run some scenarios or tests, and examine the results looking for holes in testing. Even if unit tests have 100% cc, measuring cc on common user scenarios can reveal code that may potentially need even more testing.

Another place where white box testing helps is examining data types, constants and other information to look for boundaries, special values, etc. For example, if an application has an input that takes a numeric input, a bb only approach could require the tester to "guess" at what values would be good for testing, whereas a wb approach may reveal that all values between 1-256 are treated one way, while larger values are treated another way...and perhaps the number 42 has yet another code path.

So, to answer the original question - both bb and wb are essential for good testing.

查看更多
女痞
3楼-- · 2019-01-10 02:15

Simple...Blackbox testing is otherwise known as Integration testing or smoke-screen testing . This is mostly applied in a distributed environment which rely on event-driven architecture. You test a service based on another service to see all possible scenarios. Here you cannot completely forecast all possible output because each component of the SOA/Enterprise app are meant to function autonomously. This can be referred to as High-Level testing

while

White box testing refers to unit-testing. where all expected scenarios and output can be effectively forecasted. i.e Input and expected output.This can be referred to as Low-level testing

查看更多
Melony?
4楼-- · 2019-01-10 02:20

Here is my 5 cents:

As a developer, I mostly write tests for methods (in a class) as white box tests, simple because I do not want my test to break just because I change the inner works of my code.

I only want to my tests to break if my method behavior changes (e.g. returns a different result than before).

Over the last 20 years of development, I simple got tired of doing up-to double work just because my unit tests was strongly tied to the code and I need to maintain both application code and test code.

I think making decoupling code (also when you code tests) is a very good practice.

Another 5 cents: I hardly never use mocking frameworks, because when I find it necessarily to mock something I prefer to decouple my code instead - and yes in many cases that is very possible (especially if you are not working in legacy code) :-)

查看更多
做自己的国王
5楼-- · 2019-01-10 02:21

Black Box Testing is a software testing method in which the internal structure/ design/ implementation of the item being tested is NOT known to the tester. White Box Testing is a software testing method in which the internal structure/ design/ implementation of the item being tested is known to the tester.

查看更多
登录 后发表回答