问题
What is Unit testing, Black-box testing and White-Box testing? I googled but all the explanation I found was very technical. Can anyone answer this question in a simple way with an appropriate example?
回答1:
In black box testing, you don't care how the internals of the thing being tested work. You invoke the exposed API and check the result; you don't care what the thing being tested did to give you the result.
In white box testing, you do care how the internals of the thing being tested work. So instead of just checking the output of your thing, you might check that internal variables to the thing being tested are correct.
Unit testing is a way of testing software components. The "Unit" is the thing being tested. You can do both black and white box testing with unit tests; the concept is orthogonal to white/black-box testing.
回答2:
A very non technical explaination lacking any details.... Here comes..
Blackbox Testing : Testing an application without any knowledge of how the internal application works
Whitebox Testing: Testing an application with knowledge of how the internal works, such as by having the source code side by side while you are doing your test.
Unit Testing: This is where you create tests which interact directly with your application. You would check a function in your application and
assert
that the response should return withvalue X
. Unit Tests are usually, but not always created by the developers themselves as well, whereas if a company does whitebox and blackbox testing, it can be done by anyone.
This is a very basic explaination.
回答3:
Blackbox Testing: This is always user or client based testing where testing is done based on the requirement provided. This testing is done by testers only.
Whitebox Testing: This is to verify the flow of the code base. Testing the flow of condition statement, loop statement etc. This mainly from developer prospective.
Unit Testing: This is part of white box testing as you test each methods in code with your test data and assert that. Now a days this done by testers and company looks this skill from tester where they are able to understand the code and algorithms.
回答4:
Black Box Testing:
- Tester is a human and not the developer
- Tester does not know how system was implemented *
- Tester will report an issue when the response from the system to any step of the test is not the expected result.
White Box Testing:
- Tester is a human and not the developer
- Tester does know how system was implemented *
- Tester will report an issue when the response from the system to any step of the test is not the expected result and is more likely to detect an issue with the test case itself or with the system despite receiving expected results.
Unit Testing:
- Tester is usually code that tests a particular module within a system. For example, in Java, a project may have a class named Student and a test class named StudentTest. For each of the functions in Student (like
getGrades
), StudentTest might have 0 or more functions to test them (likegetGradesTest
). This is just one such way to go about it. - Testing code typically only knows the expected output for various input for a portion of a system.
- Unit tests are often run before submitting code or run automatically when building an application to deploy. The goal is to prevent as many bugs from being introduced into the system when adding, changing or removing functionality.
* The amount of knowledge known between a black box tester and a white box tester varies from organization to organization. For example, what I consider usability testing, another company might call black box testing. A white box tester in some companies might be another developer (developer QA), whereas another organization may not allow any testing sign-offs to be completed by a developer. A black box tester could be someone who just has a list of instructions they need to follow and validate, or it could be someone who generally knows how the system works, but just not at a particularly detailed level. For example:
A black box tester may or may not identify an issue despite a test case that matches expectations, like an e-commerce test case that omits the step of collecting a guest checkout shipping address.
Essentially, white box and black box testing is rarely implemented strictly. Most organizations have unit tests, developer testing (that may or may not be formally documented - depends upon the implications of a failure), QA testers (black, white, and every shade of gray in between), and user testing / business sign-off (the people who should be involved throughout the project, but in poorly run organizations only show up at the beginning and end, and send a completed project back to design right before deployment).
来源:https://stackoverflow.com/questions/7258524/unit-testing-black-box-testing-and-white-box-testing