Easy Examples for Black, White and Gray Box Testings

Clark Jason Ngo
4 min readMar 8, 2019

--

Black box testing is a software test without knowing the internal structure of the software. Example of these are Boundary Value Analysis and Decision Table. Boundary Value Analysis is a black box test wherein it checks for errors at the boundaries of equivalence. An example of a developer code failing a boundary value analysis is when the developer mistakenly use a < instead of <= (Khan, 2011). To execute a boundary value analysis, it only needs to check the values near the boundaries. For example, if we have a boundary of 1 to 100. We only have to use 0, 1, 2, 99, 100, and 101.

Figure 1 Boundary value analysis (Software Testing Help, 2018).

Decision Table is another black box testing technique to determine whether the outcome is as expected based on a set of logic and rules that would be followed. There four items in the Decision Table: condition stub, condition entry, action stub and action entry (Nidhra & Dondeti, 2012). To give an example see Figure 2 below, a bank provides 10% interest for male and senior citizen and the rest of the people 9%.

Figure 2 Decision Table (Software Testing Help, 2018).

White box testing are tests designed for program source codes. An example of white box testing is Control Flow Testing. Control Flow Testing develops test cases and uses a control structure. Control flow graph is used to represent a control structure. In the example below, a control graph has the following but not limited to: statement node which are sequence of statements that start at an entry and ends at an exit, decision node (diamond figure) includes conditional statements that branches to 2 or more nodes and merge node (small circle figure) where branches merge. See Figure 3 for example. The test coverage for control flow testing are as follows:

  • Statement coverage (SC) — every statement execute at least once.
  • Decision coverage (DC) — every statement execute at least once and every decision in the program has been taken and had an outcome at least once.
  • Condition coverage (CC) — every statement execute at least once and every condition in the program has been taken and had an outcome at least once.
  • Decision/condition coverage (D/CC) — every statement execute at least once, decision in the program has been taken and had an outcome at least once and every condition in the program has been taken and had an outcome at least once.
  • Multiple condition coverage (MCC) — outcomes of all possible combination of conditions.
  • Path coverage (PC) — Every complete path has been executed.
Figure 3 Control flow graph (National Chung Cheng University CSIE).

Gray box testing is testing with limited knowledge of the application (Shivani & Pandya, n.d.). An example of gray box testing is functional testing. In Figure 4, we can test a calculator created with html code and make changes if a button doesn’t work and we can change the backend code (white box testing) and features with the frontend code (black box testing) (Shivani & Pandya, n.d.).

Figure 4 Calculator created from html code (Shivani & Pandya, n.d.).

Example of Unit testing

https://medium.com/@clarkjasonngo/junit-test-with-maven-in-vscode-7546eabd50f7

References

Khan, Mohd. Ehmer (2011, October). Black box and white box testing techniques –a literature review. International Journal of Embedded Systems and Applications (IJESA), 2(2), 29–50. Retrieved from http://www.airccse.org/journal/ijsea/papers/1011ijsea04.pdf

National Chung Cheng University CSIE. (n.d.). Control flow testing. Retrieved from https://www.cs.ccu.edu.tw/~naiwei/cs5812/st4.pdf

Nidhra, Srinivas & Dondeti, Jagruthi (2012, June). Black box and white box testing techniques –a literature review. International Journal of Embedded Systems and Applications (IJESA), 2(2), 29–50. Retrieved from https://pdfs.semanticscholar.org/8963/71dc9950a96b4e573edffaf0c22e3c8f67b8.pdf

Shivani, Archarya & Pandya, Vidhi (n .d.). Bridge between black box and white box — gray box testing technique. International Journal of Electronics and Computer Science Engineer), 2(1), 175–185. Retrieved from http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.303.4479&rep=rep1&type=pdf

Software Testing Help. (2018, December). Black Box Testing: An In-depth Tutorial with Examples and Techniques. Retrieved from https://www.softwaretestinghelp.com/black-box-testing/

--

--