0% found this document useful (0 votes)
0 views

Software Engineering(Mod 4)

Module 4 of Software Engineering covers coding and testing processes, including unit testing, black box testing, and debugging. It emphasizes best practices in coding, various testing types, and the importance of software reliability and quality assurance. The module also discusses the relationship between coding and testing, highlighting the significance of debugging in resolving errors.

Uploaded by

kumarabhi90067
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Software Engineering(Mod 4)

Module 4 of Software Engineering covers coding and testing processes, including unit testing, black box testing, and debugging. It emphasizes best practices in coding, various testing types, and the importance of software reliability and quality assurance. The module also discusses the relationship between coding and testing, highlighting the significance of debugging in resolving errors.

Uploaded by

kumarabhi90067
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Software Engineering

Module 4 :
1. Coding and Testing of Software: (a) Unit Testing (b) Black Box Testing
(c) White Box Testing (d) Debugging (e) Program Analysis Tools
(f) System Testing
2. Software Reliability and Quality Assurance: (a) Reliability Metric
3. Software Quality Assurance: ISO 9000 and SEI CMM and their Comparison.
-----------------------------------------------------------------------------------------------------------
1.Coding and Testing of software :
What is Coding?
• Coding (also called implementation) is the process of translating the
software design into machine-readable code using a programming
language like Java, Python, C++, etc.
• It is the actual development phase of the software life cycle.
• The goal is to create a working, efficient, and maintainable software
product.

Key Activities during Coding:


• Writing Source Code:
o Developers write code following the selected programming language
and coding standards.
• Code Review:
o Other developers or team leads review the code for quality, errors,
and best practices.
• Code Optimization:
o Making the code more efficient by removing redundancies and
improving performance.
• Integration:
o Integrating different modules so they work together as a complete
system.
• Documentation:
o Developers document the code to explain logic, functionality, and
interfaces.

Best Practices During Coding:


• Follow coding standards and naming conventions.
• Write modular and reusable code.
• Keep code simple and readable (KISS principle: Keep It Simple, Stupid).
• Write comments where necessary.
• Use version control systems like Git to manage code changes.
• Perform unit testing while coding.

Example:
Imagine you are developing a Calculator App:
• Design defines a module for Addition, Subtraction, etc.
• Coding phase means actually writing the function in Java:
java
Copy code
public int add(int a, int b) {
return a + b;
}
This function would then be tested and integrated into the whole calculator.
Testing in Software Engineering

What is Testing?
• Testing is the process of verifying and validating that the software works as
intended and is free of bugs.
• It ensures the quality, security, functionality, and performance of the
software.

Objectives of Testing:
• To find errors and bugs.
• To ensure the software meets the requirements.
• To ensure reliability and performance under different conditions.
• To ensure the software is secure and usable.

Types of Software Testing:

1. Unit Testing:
• Tests individual modules or functions.
• Done by developers.
• Example: Testing the add() function separately.

2. Integration Testing:
• Tests how different modules work together.
• Example: Testing if the addition and subtraction modules integrate
properly in the calculator.
3. System Testing:
• Tests the entire system as a whole.
• Example: Testing the complete Calculator App.

4. Acceptance Testing:
• Done to check if the system meets business requirements.
• Done by end-users or clients.

5. Regression Testing:
• Done after changes to the code, to ensure new code has not broken
existing features.

6. Performance Testing:
• Tests if the software is fast, stable, and responsive under load.

7. Security Testing:
• Checks the software for vulnerabilities and security risks.

Phases of Testing:
1. Test Planning:
o Decide what to test, how to test, and who will test.
2. Test Case Development:
o Write test cases that describe input, action, and expected output.
3. Test Execution:
o Execute the tests manually or using automated tools.
4. Defect Reporting:
o Log any bugs or issues found during testing.
5. Defect Fixing:
o Developers fix the bugs.
6. Retesting and Regression Testing:
o Test again to verify bug fixes.
7. Final Testing and Closure:
o Verify the software is ready for release.

Testing Example:
Suppose the Calculator App you coded earlier:
• You run a test case to check if add(2, 3) returns 5.
• If it does, the test passes.
• If it returns anything else, the test fails, and you must debug the code.

Relationship Between Coding and Testing:

Coding Testing

Developers create the software. Testers (or developers) verify the software.

Focuses on implementing Focuses on validating correctness and


functionality. reliability.

Errors are introduced. Errors are detected and corrected.

Produces source code. Produces test reports and bug lists.

• Both are dependent: Good coding simplifies testing, and good testing
ensures coding is successful.
What is Unit Testing?
• Unit Testing is a software testing technique where individual units or
components of a software are tested in isolation.
• A unit is usually the smallest testable part of an application — like a
function, method, or class.
• It validates that each unit of the software performs as expected.
• Generally done by developers during the development phase (sometimes
before, in Test-Driven Development (TDD)).

Objectives of Unit Testing:


• Ensure that individual components work correctly.
• Catch bugs early at the unit level before integrating them.
• Improve code quality and design.
• Make future changes easier and safer.
Characteristics of Unit Testing:
• Isolated: Each test focuses only on one unit, independent of others.
• Automated: Mostly done using automated testing frameworks (like JUnit,
pytest, etc.).
• Fast: Unit tests run very quickly since they are small and isolated.
• Repeatable: Can be executed again and again without manual
intervention.

Process of Unit Testing:


1. Identify the Unit to be tested (e.g., a function or method).
2. Write Test Cases with input values and expected outputs.
3. Execute the Test and compare the actual output with the expected
output.
4. Fix the Code if the test fails.
5. Re-test after fixing bugs.

Example of Unit Testing:


Suppose you have a simple Java method for addition:
java
Copy code
public int add(int a, int b) {
return a + b;
}
Now you write a unit test for it:
java
Copy code
import static org.junit.Assert.assertEquals;
import org.junit.Test;

public class CalculatorTest {

@Test
public void testAdd() {
Calculator calc = new Calculator();
int result = calc.add(2, 3);
assertEquals(5, result); // Checking if 2 + 3 = 5
}
}

• If result = 5, test passes.

• If result ≠ 5, test fails, meaning there’s a bug in the add() function.

Popular Unit Testing Frameworks:

Language Frameworks

Java JUnit, TestNG

Python unittest, pytest

JavaScript Jest, Mocha

C# NUnit, MSTest

PHP PHPUnit

Advantages of Unit Testing:


• Catches bugs early during development.
• Simplifies debugging since errors are caught at the unit level.
• Helps improve software design (forces you to write modular code).
• Reduces overall testing cost by catching errors early.
• Speeds up integration by ensuring individual pieces work correctly.

Disadvantages of Unit Testing:


• Cannot find integration errors (interaction between modules).
• Does not guarantee that the system as a whole is correct.
• Requires time and effort to write and maintain test cases.
• Might give a false sense of security if tests are not written properly.

Example Scenario:
Suppose you are building a Banking Application:
• You write a deposit() method.
• You create unit tests to check:
o Depositing a positive amount increases the balance.
o Depositing a zero or negative amount throws an error.
• These tests ensure that your deposit logic is always working.

Summary Table

Aspect Unit Testing

Focus Individual function/module/class

Performed by Developers

Tools JUnit, pytest, unittest, etc.


Aspect Unit Testing

Purpose Catch bugs early and improve code quality

Example Testing an add(a, b) function

What is Black Box Testing?


• Black Box Testing is a software testing technique where the tester
evaluates the functionality of the software without looking into the
internal code, logic, or structure.
• The tester only knows the inputs and the expected outputs — they don't
care how the output is generated internally.
• It is primarily focused on "what" the system does, not "how" it does it.

Characteristics of Black Box Testing:


• No knowledge of internal code is required.
• Focus on outputs generated against any input.
• Tests functional requirements (sometimes also non-functional like
performance).
• Test cases are designed based on requirements and specifications.
• Done at various levels: Unit Testing, Integration Testing, System Testing,
Acceptance Testing.
• Often performed by testers, not necessarily developers.

Key Techniques in Black Box Testing:

Technique Description

Equivalence Dividing input data into valid and invalid partitions and
Partitioning testing one from each group.
Technique Description

Boundary Value Testing at boundaries between partitions (e.g., minimum,


Analysis maximum values).

Decision Table Testing different combinations of inputs with expected


Testing outputs.

State Transition
Testing the system’s behavior for different states.
Testing

Testers use their experience to guess where errors might


Error Guessing
happen.

Advantages of Black Box Testing:


• Tester’s view is unbiased by internal code.
• Helps validate requirements and ensure correct functionality.
• Can be performed by non-programmers.
• Useful for large codebases where checking internal logic is impractical.

Disadvantages of Black Box Testing:


• Limited coverage: Might miss some internal errors or paths.
• Difficult to design test cases if requirements are incomplete.
• Cannot guarantee that all logical errors are found.

Example of Black Box Testing:


Imagine you are testing a Login Page:
• Input: Username and Password fields.
• Expected Output:
o If correct username/password → Login successful.
o If wrong credentials → Error message displayed.
• Tester’s Role:
o They will not check how the system authenticates internally.
o They will enter various inputs (valid/invalid) and observe outputs.
Test Cases:

Test Input Expected Output

Correct credentials Dashboard opens

Incorrect password "Invalid password" message

"Fields cannot be empty"


Blank fields
message

Testers don't care how the input is processed internally — only whether the
output is correct.

Black Box Testing in Real World:


Imagine an ATM Machine:
• Insert card → Enter PIN → Select Amount → Cash Dispensed.
• As a black-box tester:
o You test whether the correct cash amount is dispensed.
o You test if wrong PINs block the card after 3 attempts.
o You don't inspect the ATM's internal software code.

Comparison with White Box Testing:

Feature Black Box Testing White Box Testing

Knowledge of Code Not required Required


Feature Black Box Testing White Box Testing

Focus Functionality (outputs) Internal logic and paths

Done by Testers Developers/testers

Example Testing login button Testing login algorithm

Summary

Aspect Black Box Testing

Focus Inputs and expected outputs

Internal Code Knowledge Not required

Test Designer Tester or QA Engineer

Used for Functional testing, system testing

Example Testing a login page, ATM transactions

Key Takeaway:
"Black Box Testing ensures that the software works according to the user’s
expectations without worrying about how the code is written internally."
What is Debugging?
• Debugging is the process of identifying, analyzing, and removing errors
(bugs) from software code.
• It begins after testing detects a defect and ends when the issue is
completely resolved.
• Debugging ensures that the software functions as intended without
crashing or producing wrong results.
• It is an integral part of software development and maintenance.
Objectives of Debugging:
• Locate the exact cause of a problem in the code.
• Understand why and how the error occurred.
• Fix the problem without introducing new bugs.
• Ensure that the fix works correctly across all scenarios.

Steps in Debugging:
1. Identify the Problem
o From test failure or bug report.
2. Reproduce the Error
o Run the program under the same conditions to confirm the issue.
3. Isolate the Source
o Use logs, print statements, or debuggers to narrow down the faulty
part.
4. Analyze the Root Cause
o Understand why the bug happened (logic error, typo, memory leak,
etc.).
5. Fix the Code
o Modify the code to correct the error.
6. Re-test
o Run the code again to ensure the bug is resolved and no new bugs
are introduced.

Types of Errors Debugged:


• Syntax Errors: Mistakes in the code syntax.
• Logical Errors: Correct syntax, but incorrect logic.
• Runtime Errors: Occur during execution (e.g., divide by zero).
• Semantic Errors: The meaning of code is incorrect.

Debugging Techniques:
• Print Debugging: Using print() or console.log() to trace program flow and
variables.
• Using Debuggers: Built-in tools (like those in IDEs – VS Code, Eclipse,
PyCharm) that allow breakpoints and step-through execution.
• Rubber Duck Debugging: Explaining your code to someone (or even a
rubber duck!) to identify issues.
• Logging: Use of log files to track execution and errors.
• Backtracking: Going back from the point of failure to find the bug.

You might also like