Thursday 29 March 2018

Program Testing and Debugging

A software bug (or just "bug") is an error, flaw, mistake, failure, fault or "undocumented feature" in a computer program that prevents it from behaving as intended (e.g., producing an incorrect result).

Most bugs arise from mistakes and errors made by people in either a program's source code or its design and a few are caused by compilers producing incorrect code.

Formal Program Testing
                The software industry is primarily concern with logical errors and hidden run-time errors. Companies expend enormous effort to find the errors before the release. To fix a bug after the release cost a 100 times more; patches must be designed and ship out.Besides the customer are not very happy. So, there is the necessity of program testing before it goes to the end user.
   The industry is concerned with Verification and Validation :
               Validation or appropriate :
                  Techniques for insuring validation :
                         Inspection code at a high level
                         Have the user/customer test software
                         Requires good software specification

                Verification or correctness :
                         Is the program producing the correct answers ?
                         Techniques for insuring verification :
                              Code walk through of inspection

    Testing is the primary technique for the above two Vs :
        Testing uses input data and observes output.
             There may be additional output then in the final product.
             The evaluation may include more then just the correctness of the output.
             Testing can be at the component level or integrated level.

   Debugging is a methodical process of finding and reducing the number of bugs or defects, in a computer program or a piece of electronic hardware thus making it behave as expected. Debugging tends to be harder when various subsystem are tightly coupled, as changes in one may cause bugs to emerge in another.

Difference between Testing and Debugging

Types of Program Errors
  There are three basic errors :
    1. Syntax/Compilation error
    2. Run-time exception error
    3. Logical error

Syntax / Compilation Error
   Error during compiling prevents getting a compiled code. Modern compilers indicate well the location of the error. Sometimes problems with delineators such as semicolons in C or brackets in C++.

Run-time Exception Error
  When you get an error message while running the compiled code. Java gives good error messages indicating the location of the error but that might not be the location of the actual error.Some languages, such as C seem to have only one type of error; segmentation fault or Fortran, index out of bounds.

Logical Error
  These errors are the hardest to correct or detect. The program "runs" but the output is not correct.
Tools for detecting and fixing logical error :
      1. Choose test cases well. Try to cover everything with small cases. Try one big case.
      2. Print intermediate value. Use a boolean variable to turn on and off debug printing.
      3. Walk though. Play computer in front of an audience (if you can) and suspect all code especially uncommitted code.

Logical errors generally occur at :
Loops : 
    Check the range of for loops and the boolean expression of while loop.
Ifs :
    Check complicated boolean expressions (more than one variables) and especially if you are using negation.


Post a Comment

Popular Posts


AI (27) Android (24) AngularJS (1) Assembly Language (2) aws (17) Azure (7) BI (10) book (4) Books (114) C (77) C# (12) C++ (82) Course (60) Coursera (176) coursewra (1) Cybersecurity (22) data management (11) Data Science (87) Data Strucures (6) Deep Learning (9) Django (6) Downloads (3) edx (2) Engineering (14) Excel (13) Factorial (1) Finance (5) flutter (1) FPL (17) Google (19) Hadoop (3) HTML&CSS (46) IBM (25) IoT (1) IS (25) Java (92) Leet Code (4) Machine Learning (44) Meta (18) MICHIGAN (5) microsoft (3) Pandas (3) PHP (20) Projects (29) Python (740) Python Coding Challenge (188) Questions (2) R (70) React (6) Scripting (1) security (3) Selenium Webdriver (2) Software (17) SQL (40) UX Research (1) web application (8)


Person climbing a staircase. Learn Data Science from Scratch: online program with 21 courses