What is a white box test
White box testing is testing the internal architecture, design, and code of a software solution. In this type of test, the tester can see the code. It focuses primarily on validation through the input and output of an application, improving design and usability, and enhancing security. White-box testing, also known as transparent testing, open-box testing, structural testing, and code-based testing, is typically performed by developers.
It is an important part of software testing. The equivalent of black box testing involves testing from an external or end-user type perspective. White-box testing, on the other hand, is based on the internal workings of the application and is built around internal testing.
What is verified in a white box test
White-box testing involves testing the following software code:
- Internal security
- A path or structure during encoding
- Through a particular input stream of code
- The expected output
- Conditional loop function
- Test each statement, object, and function separately
Testing can be done at the system, integration, and unit levels of software development. One of the basic goals of white-box testing is to validate the workflow of the application. It involves testing a series of predefined inputs against the expected or expected output so that bugs in the program can be found when a particular input does not produce the expected output.
How do white-box tests work
To simplify white-box testing, break it down into two basic steps. This is what testers do when testing applications using white-box testing techniques:
Step 1: Understand the source code
The first thing testers often do is learn and understand the application’s source code. Because white-box testing involves testing the inner workings of an application, testers must have a good understanding of the programming language used in the application being tested. Also, testers must have a high level of knowledge of secure coding. Security is usually one of the main goals of testing software. Testers should be able to spot security issues and prevent attacks by hackers and geeky users who may intentionally or unintentionally inject malicious code into the application.
Step 2: Create test cases and execute them
The second basic step in white-box testing involves testing the application’s source code to verify the correct process and structure. One way is to write more code to test the application’s source code. Testers will develop very few tests for each procedure or series of procedures in the application. This approach requires a deep understanding of the code by the tester and is usually done by the developer.
White-box test example
An addition Demo:
def add(int a, int b) {
int result = a + b;
if (result > 0) print result
else print(-result);
}
Copy the code
The goal of white-box testing is to validate all decision branches, loops, and statements in your code.
To execute the statements in the above code, the white box test case should be:
A = 1, B =1
A = -1B = -3
Copy the code
White box testing techniques
The main technique of white box testing is code coverage analysis. Code coverage analysis eliminates blind spots in test case suites. It identifies an area of the program that is not executed by a set of test cases. Once blind spots are found, test cases can be created to validate untested parts of the code, thereby improving the quality of the software product.
Automated tools are available to perform code coverage analysis. Here are some coverage analysis techniques
Statement coverage: This technique requires that all possible statements in your code be tested at least once during software engineering testing.
Branch coverage: This technique examines every possible path (if-else and other conditional loops) to a software application.
In addition to the above, there are many types of coverage, such as conditional coverage, multiple conditional coverage, path coverage, function coverage, and so on. Each technique has its own advantages and tries to test (cover) all parts of the software code. With statement and branch coverage, 80-90% code coverage is typically achieved.
Here’s what I’ve written about coverage before:
- Interface Test Code Coverage (JACOCO) solution sharing
- Jacoco could not read the source path solution in the build.xml configuration
- Create code coverage reports using the JaCoCo Maven plug-in
- About Test Coverage
Type of white box test
White-box tests include several types of tests used to evaluate the usability of applications, code blocks, or specific software packages. Listed below –
Unit testing
This is usually the first type of testing you do on your application. Unit tests are performed as each unit or block of code is developed. Unit testing is essentially done by programmers. As a software developer, you just develop a few lines of code, a single function or object, test it to make sure it works, and then move on to unit testing to help identify most bugs early in the software development life cycle. Errors found at this stage are cheaper and easier to fix.
Here are the unit testing articles:
- Learn from unit test standards
- Unit test cases
- Brief Introduction to Unit Testing
Testing for memory leaks
Memory leaks are a major cause of slow application performance. If your software application is running slowly, a quality assurance expert with extensive experience in detecting memory leaks is critical.
other
- White box penetration testing: In this test, the tester/developer has complete information about the application source code, detailed network information, IP addresses involved, and information about all servers on which the application is running. The goal is to expose security threats by attacking code from multiple angles
- White-box mutation testing: Mutation testing is typically used to discover the best coding techniques for extending software solutions
Advantages of white box testing
- Code optimization by finding hidden bugs.
- White-box test cases can be easily automated.
- Testing is more thorough because it typically covers all code paths.
- Even without a GUI, you can start testing early in the SDLC.
Disadvantages of white box testing
- White-box testing can be complex and expensive.
- Developers who typically execute white-box test cases hate it.
- White-box testing requires specialized resources and a detailed understanding of programming and implementation.
- White-box testing is time consuming, and large programming applications can take a lot of time to fully test.
conclusion
White-box testing can be complex. The complexity involved has a lot to do with the application being tested. A small application that performs a single simple operation can be white-box tested in minutes, while a large programming application can take days, weeks or even longer to fully test.
- Solemnly declare: the article was first published in the public number “FunTester”, prohibit third parties (except Tencent cloud) reprint, published.
Technical articles selected
- Linux performance monitoring software Netdata Chinese version
- Performance Testing Framework third edition
- How to perform performance tests on a Linux command line interface
- Graphic HTTP brain map
- Output test data graphically in performance tests
- In manometry, the delay of asynchronous write interfaces is measured
- Multiple login methods quantitative performance test scheme
- JMeter throughput error analysis
No code articles selected
- Programming thinking for everyone
- JSON based
- 2020 Tester self-improvement
- Pitfalls to Avoid for Beginners to Automation (PART 1)
- Pitfalls to Avoid for Beginners to Automation (Part 2)
- How to become a Full stack automation engineer
- Left shift test
- Manual testing or automated testing?