Back 

Testing your programs questions and answers

Questions

Q1. Give an example of a syntax error and describe how syntax errors are found.
Q2. Give an example of a logical error and describe how you find logical errors.
Q3. Give an example of when a run-time error might occur.
Q4. What is the difference between black box and white box testing?
Q5. What is the difference between alpha and beta testing?
Q6. What is meant by unit testing?
Q7. Explain the need for integration testing.
Q8. Describe the tools that can be used to track down a logical error.
Q9. What is meant by ‘stepwise refinement’?
Q10. How do programmers make their code as readable as possible?

Answers

Q1. An example of a syntax error is Pint instead of Print. Translator diagnostics are used to find syntax errors.
Q2. An example of a logical error is when you type 3 + 4 but meant 3 * 4. Logical errors are found through careful black and white box testing and by dry running programs using trace tables.
Q3. A run time error might occur if you had an instruction temp / 0.
Q4. With white box testing, you can see the code and design tests so that you test each path through the code. With black box testing, you can’t see the code. You use the functional description / requirements specification to design tests, to test whether inputs give you the required outputs.
Q5. Alpha testing is done in-house whereas beta testing makes use of external special customers, reviewers, textbook writers, focus groups and so on.
b Whenever a module of code (or subroutine, or unit, or function, or procedure, or whatever other name you want to give to the block of self-contained code) is written, it needs to be tested. Testing can be done using black or white box testing, as discussed earlier. Whether you use black box or white box testing, testing an individual module of code is known as ‘unit testing’.
Q7. Once modules of code are tested using unit testing, they need to be combined and tested together. It is possible that two fully tested modules (tested individually using unit testing) will produce a problem when they are combined and asked to work together. Bringing modules together and checking that there are no unintentional problems is known as ‘integration testing’.
Q8. Logical errors can be tracked down by setting breakpoints, running the code up to the breakpoint and then stepping through the code, one line at a time, whilst looking at variables, tests and so on. You can then often spot when something goes wrong. Cross-referencing can be used to check that all identifiers have been used properly. You can often find errors where other methods fail using trace tables and dry running code by hand on paper.
Q9. Whatever the language being used, it will be easier to understand a program if it has been broken down into small modules, with each of the modules performing ideally just one task and coded up as a standalone piece of code. The modules are effectively standalone units of code that can, however, interact with other modules of code. The approach of splitting up a big problem into a smaller problem is known as 'top-down programming' or ‘stepwise refinement’.
Q10. Code can be made easier to read by using meaningful identifiers, spacing out code, using comments, indentation and modular programming.

 

Back