CSC 205
CSC 205
Debugging is the process of identifying and removing errors from computer software or
hardware. It is essential for ensuring that programs run correctly and efficiently.
Testing involves executing a program with the intent of finding errors. It is crucial for verifying
that the software meets the requirements and is free of bugs.
Importance of debugging and testing
• They enhance software reliability and performance
• They prevent future issues
• They maintain code quality
Types of Errors
Errors in programming can be categorized into three main types:
• Syntax errors: Syntax errors are mistakes in the code structure, such as missing semicolons
or incorrect indentation, and are detected by the compiler or interpreter
• Runtime errors: Runtime errors occur during program execution, such as division by zero or
null pointer dereferences, and can cause the program to crash or produce incorrect results
• Logical errors: Logical errors are mistakes in the program's logic that produce incorrect
results. The program runs without crashing, but the output is not as expected.
Debugging Techniques
Various debugging techniques can be employed to identify and fix errors in the code.
• Using print statements is a simple but effective method: where print statements are inserted in
the code to output variable values and program flow.
• Debugging tools, such as IDEs with built-in debuggers (like Visual Studio, Code Blocks, and
Eclipse), provide more advanced debugging capabilities.
• Setting breakpoints allows the program to pause execution at specific points, enabling step-by-
step inspection of variable values and program flow.
• Analyzing error messages and stack traces helps identify the source of the problem by tracing
the sequence of function calls that led to the error.
Common Debugging Strategies
Effective debugging strategies involve;
• Understanding the problem: entails reproducing the error and gathering information
about the conditions under which it occurs.
• Reproducing the error: involves creating a test case that consistently triggers the error.
• Isolating the problem: Isolating the problem can be done using a binary search method
to narrow down the code section causing the error, or by commenting out code sections
and re-enabling them gradually to pinpoint the issue.
• Fixing the bug: once the problem is isolated, the code can be modified to correct the
error.
• Testing the fix: running tests ensures that the error is resolved and that the fix works
under various conditions.
Types of Testing
Testing is an essential aspect of software development, with various types including
• Unit testing: involves testing individual components or functions of the code.
• Integration testing: checks how different components work together
• System testing: verifies the complete system to ensure it meets the requirements.
Testing can be performed manually or automatically.
• Manual testing is done by human testers and is suitable for exploratory testing. In manual
software testing, a tester tests the software by following a set of predefined test cases. In this
testing, testers make test cases for the codes, test the software, and give the final report about
that software. Manual testing is time-consuming because it is done by humans, and there is
a chance of human errors.
• Automated testing uses scripts and tools to automate test execution, making it suitable for
repetitive tests. It involves using special software for tasks that people usually do when
testing.
Comparison between Unit Testing, Integration Testing and System Testing
Aspect Unit Testing Integration Testing System Testing
Definition Testing individual Testing the interactions Testing the entire system
components or functions between integrated as a whole to ensure it
in isolation components meets requirements
Scope Narrow scope: single Medium scope: combined Broad scope: the
function or module units or modules of the complete application or
application system
Purpose Ensure that each Ensure that combined Ensure that the entire
component works components function system works as
correctly on its own together correctly intended
Performed by Developers Developers or testers Testers
Test Cases Focus on individual Focus on interaction Focus on end-to-end
functions and methods between integrated units scenarios and user
journeys
Complexity Low complexity Medium complexity High complexity
Example Testing a function to Testing how the grade Testing the whole
calculate a single calculation and student grading system,
assignment grade (e.g., 85 record modules work including inputting
-> B) together (e.g., combining scores, calculating final
assignment scores for a grades, and generating
final grade) report cards
Unit Tests
Unit tests check a small part of the code, such as a single function or method, and are beneficial
for detecting issues early in the development process, facilitating code changes and refactoring,
and improving code reliability and quality. A typical unit test follows a structure:
Declaring variables
int float
double char
bool string
if statement syntax
If…else statement syntax
>>>