Skip to Content
Pragmatic Software Testing: Becoming an Effective and Efficient Test Professional
book

Pragmatic Software Testing: Becoming an Effective and Efficient Test Professional

by Bulverde Rex Black Rex Black Consulting Services Texas
February 2007
Intermediate to advanced
366 pages
7h 49m
English
Wiley
Content preview from Pragmatic Software Testing: Becoming an Effective and Efficient Test Professional

Chapter 22. Control-Flow Testing Exercise

It’s time to apply the white-box control-flow testing concepts you’ve learned to a simple program. In Listing 22-1, you’ll find a simple C program that converts hexadecimal character input into an integer. It displays the number of hexadecimal characters converted and their value (in hexadecimal). It ignores nonhexadecimal characters. This program will run on a Windows or Linux system if you have a compiler available to you.

The exercise is in three parts:

  1. Understand the number of potential test cases.

  2. Create a set of test cases for full statement, branch, condition, and loop coverage.

  3. Calculate the McCabe complexity, write the basis paths, and create the basis tests.

I suggest 30 minutes as a time limit. When you’re done, keep reading to see my solution.

Example 22-1. Hex converter program

1. main() 2. /* Convert hex digits to a number */ 3. { 4. int c; 5. unsigned long int hexnum, nhex; 6. 7. hexnum = nhex = 0; 8. 9. while ((c = getchar()) != EOF) { 10. switch (c) { 11. case '0': case '1': case '2': case '3': case '4': 12. case '5': case '6': case '7': case '8': case '9': 13. /* Convert a decimal digit */ 14. nhex++; 15. hexnum *= 0x10; 16. hexnum += (c - '0'); 17. break; 18. case 'a': case 'b': case 'c': 19. case 'd': case 'e': case 'f': 20. /* Convert a lower case hex digit */ 21. nhex++; 22. hexnum *= 0x10; 23. hexnum += (c - 'a' + 0xa); 24. break; 25. case 'A': case 'B': case 'C': 26. case 'D': case 'E': case 'F': 27. /* Convert an upper ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Best Practices for the Formal Software Testing Process: A Menu of Testing Tasks

Best Practices for the Formal Software Testing Process: A Menu of Testing Tasks

Rodger D. Drabick
How We Test Software at Microsoft®

How We Test Software at Microsoft®

Alan Page, Ken Johnston, and Bj Rollison
The Expert Test Manager

The Expert Test Manager

Rex Black, James L. Rommens, Leo van der Aalst

Publisher Resources

ISBN: 9780470127902Purchase book