gbrlrz017 / test-cases

test-case
0 stars 0 forks source link

Test Cases

What is a “test case”?

The IEEE defines test case writing as “Documentation specifying inputs, predicted results, and a set of execution conditions for a test item.” And the computer scientist and author, Glenn Meyers, says that a test case is “a process of executing a program with the intent of finding an error.” A test case essentially checks that a program works as it should.

Finding and fixing bugs is an important part of the programming process. A bug you didn't know existed can come back to haunt you later. For example, consider NASA's Mars Climate Orbiter which, in 1998, was tasked with looking for water and studying the weather on Mars. Apparently, some of its programmers had been working in SI units while others had been working in English units. The result from this lack of communication was a bug that made the thrusters 4.45 times more powerful than they should have been. This $327.6 million project was consequently lost in space, most likely in pieces.

No program is ever perfect (not even those that NASA writes). But a good programmer makes a habit out of making sure her or his program is as bugless as possible.

The aim of test case writing is to separate a program into small, important units that produce a quantifiable result. For example, the quality of our shell can be measure by test cases that examine functionality and usability. Test case writing should make knowing how well a program works as easy and efficient as possible. Here are some questions that test cases should address:

  1. What scenarios have been tested and which still need to be tested?
  2. Which parts of the program are stable? What parts are unstable?
  3. Where does the program need more work?
  4. Have enough possibilities and input combinations been tested?
  5. Is there appropriate error checking and error messages? (negative test cases)
  6. Is the User Interface (UI) similar enough to Bash's UI? (the command prompt for example)
  7. Are the required features working? (the assignment specifications)
  8. Have the possible scenarios been documented? Are these scenarios in a working state?
  9. Are the tests strong enough? Are the tests finding issues in the program?
  10. What is the overall quality of the segment of the shell you just implemented? The entire shell?

Types of Test cases:

Test Design Strategies:

The following are useful strategies for test case writing.

Combining two or more of these approaches at a time is likely to yield good results.

Writing Test Cases:

The main idea behind writing test cases is to be as effective and to the point as possible. There is no need to get overly complex as long as the essential parts of the program are tested adequately.

screenshot from 2014-12-17 01 26 31

The above template allows the tester to document test cases and useful information that goes along with them in a clean fashion.

Here is an example of how to fill in the test table. The program in question implements a basic version of the Bash command shell using execvp, fork, and waitpid. (see the requirement specs for this program). These are only some of the possible test cases I tried.

screenshot from 2014-12-16 23 38 05 screenshot from 2014-12-16 23 38 46 screenshot from 2014-12-16 23 39 01

Notice the trend in the failed test cases: parsing fails when connectors have no spacing between them and other text, like "..-f&&ls...". Having it all documented allows the tester to see the extent of the problem: the issue extend to all three connectors, ; || and &&, which can be considered boundary values.

Writing test cases requires some creativity on the tester's part, but they shouldn't be the most difficult part of creating a command shell. The above tips and tools will help make this a bit easier.