0% found this document useful (0 votes)
8 views19 pages

LECTURE 2 STN

The document provides an overview of software testing and quality assurance, detailing the concept of test cases, testing activities, and various levels of testing such as unit, integration, system, and acceptance testing. It emphasizes the importance of test automation, its benefits, and challenges, while also discussing unit testing techniques and tools, including static and dynamic testing, debugging, and mutation testing. Additionally, it highlights the Test-Driven Development (TDD) approach in Extreme Programming (XP) and the use of the JUnit framework for effective unit testing.

Uploaded by

Hesham MosaAd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views19 pages

LECTURE 2 STN

The document provides an overview of software testing and quality assurance, detailing the concept of test cases, testing activities, and various levels of testing such as unit, integration, system, and acceptance testing. It emphasizes the importance of test automation, its benefits, and challenges, while also discussing unit testing techniques and tools, including static and dynamic testing, debugging, and mutation testing. Additionally, it highlights the Test-Driven Development (TDD) approach in Extreme Programming (XP) and the use of the JUnit framework for effective unit testing.

Uploaded by

Hesham MosaAd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Software Testing and Quality

Assurance
Chapter 1
Basic Concepts and Preliminaries
WHAT IS A TEST CASE?
 A test case is a simple pair of <input, expected outcome>. For
example, if a program is expected to compute the square root of
nonnegative numbers, the test cases might be:

 In stateless systems, the outcome depends only on the current


input. In state-oriented systems, the outcome depends on both
the current input and the system's current state.
 Example: ATM Test Case (TS1)
 In a state-oriented system like an ATM, the test case involves a
sequence of inputs and expected outcomes:
 Check balance: <check balance, $500.00>
 Withdraw amount: <withdraw, $200.00>
 Check balance after withdrawal: <check balance, $300.00>
 In this example:
 Input 1 checks the current balance.
 Input 2 withdraws $200.00.
 Input 3 verifies that the balance is now $300.00 after the
withdrawal.
 Concept of Complete Testing
 Complete testing means ensuring that there are no undiscovered
faults in the program by the end of testing. However, it's practically
impossible to achieve complete testing for most systems due to the
following reasons:
 Large input domain:
 The program may have a vast range of valid and invalid inputs that
can't all be tested due to timing or specific conditions for validity.
 Design complexity:
 The system’s design may involve complex assumptions or constraints
that make it impossible to test every possible scenario.
 Execution environments:
 Testing all possible environments (e.g., different weather,
temperature, altitude) where the software might run is unfeasible.
Testing Activities
 Select Inputs:
 The first activity is to select the inputs for the test. These inputs are based on the
system’s requirements and the objectives of the test.
 Inputs are chosen depending on the type of test being performed, like testing a
specific feature or the system's behavior under certain conditions.
 Select Environment:
 The second activity is to select the testing environment. The environment
includes all external factors like hardware, operating systems, networks, etc.
 It’s important to test the system in an environment that closely resembles the real-
world conditions in which it will operate.
 Execute the Test:
 In this step, the test is actually executed using the chosen inputs and environment.
 This involves running the program or system in the selected environment with the
predefined inputs.
 Observe the Outcome:
 After executing the test, we observe the outcome and compare it with the
expected result.
 If the outcome matches expectations, the system is working as intended. If it doesn’t,
the issue is identified and corrections are made.
Test Levels
 Testing is performed at different levels to ensure the software
product works as expected. These levels of testing go through
four stages before the product is deployed:
 Unit Testing:
This is the first level of testing and focuses on testing individual components or units
of the program, such as functions, methods, or classes. The goal is to ensure each unit
works correctly in isolation.
 Integration Testing:
Once individual units are tested, the next step is to test the interactions between
those units. This ensures that when the individual units are combined, they work
correctly as a system.
 System Testing:
After integration testing, the whole system is tested. The goal is to validate that the
integrated components work together as expected within the complete system
environment.
 Acceptance Testing:
This level of testing is done by the customer or the client. It is performed to verify
whether the system meets the customer's needs and requirements. There are two
types of acceptance testing:
 User Acceptance Testing (UAT): Done by the end-users to ensure the system meets
their requirements.
 Business Acceptance Testing (BAT): Performed by the business to ensure the
system supports the business processes.
Test Tools and Automation
 Manual Testing vs. Automated Testing:
Manual testing is slow and labor-intensive because tests are created and
executed by hand.
Automated testing uses tools to run tests faster and more efficiently,
especially for repetitive tasks, reducing human errors.
 Benefits of Test Automation:
I. Increased productivity: Automated tests help testers work faster.
II. Better coverage for regression testing: Automated tests can cover
more cases to ensure that new changes don't break existing functionality.
III. Reduced test duration: Automated tests run faster, saving time on
each test cycle.
IV. Reduced software maintenance cost: Automated tests can be
reused, lowering overall costs in the long term.
V. Increased effectiveness of test cases: Automation can handle
complex tests more reliably, making the testing process more effective.
How Test Automation Improves Testing:
 It lets testers focus more on developing automated test cases
instead of repetitive manual testing.
 It speeds up tests, especially regression tests, and allows testing
in complex environments that would be hard to replicate
manually.
Regression Testing:
 Regression testing involves re-running previous tests to ensure
that new changes don’t introduce new problems.
 Automation speeds up regression testing by reusing existing test
cases and making the process more accurate
Challenges in Automation:
 Automation can't replace manual testing completely. Some tasks
require human judgment, creativity, and adaptability.
 Automated tests can’t detect all variations that humans can, especially
when decisions depend on changing conditions.
Key Considerations for Successful Test Automation:
 Tools and infrastructure: The right test tools and infrastructure
must be in place for automation.
 Well-defined test cases: Only clear, well-defined test cases can be
automated effectively.
 Team experience: The team must be experienced in both manual
and automated testing to avoid making the process more
complicated.
 Manual testing still required: Some tests, especially exploratory
or subjective tests, may still need to be done manually.
Requirements for Test Automation:
 Test cases should be well-defined: For automation to be effective,
test cases need to be clearly defined.
 Tools and infrastructure must be in place: The necessary tools
and infrastructure should be ready.
 Team readiness: The team must be properly trained to handle both
automated and manual testing effectively.
Ch. 2: Unit Testing

 Unit testing is the process of testing individual components (or


units) of a program to ensure they work correctly on their own. A
unit can be a function, method, or class. The primary goal of unit
testing is to verify that each part of the program behaves as
expected before integrating it with other parts of the system.
 By testing units in isolation, we can detect and fix problems early
in development, making it easier and more efficient than finding
bugs in later testing phases or during integration.
Types of Unit Testing

 Static Unit Testing:


 Static testing involves reviewing the code without executing it. The aim is to
detect potential issues like incorrect logic or improper code structure before
running the program.
 This can be done through code inspections or walkthroughs, where team
members go through the code line by line.
 Example of Static Testing:
A code review can help identify problems early, even before executing
the code. For example, inspecting the logic of a sorting algorithm for edge
cases might uncover potential errors.
 Dynamic Unit Testing:
 Dynamic testing involves actually running the code and comparing its output
to the expected result. If the output doesn't match expectations, it indicates a
problem that needs fixing.
 Dynamic tests can be executed manually or with the help of testing tools.
 Example of Dynamic Testing:
Testing a function that calculates the sum of two numbers:
public class Calculator {
public int add(int a, int b) {
return a + b;
}
}
Test Case:
 Inputs: a = 2, b = 3
 Expected Output: 5
Debugging During Unit Testing
During unit testing, developers often face errors. The process of identifying
and fixing these errors is called debugging. It involves several steps:
 Reproducing the Error:
 First, developers need to reproduce the error by analyzing logs and test
outputs.
 Forming Hypotheses:
 Developers form hypotheses about the possible causes of the issue based on
their observations.
 Testing the Hypotheses:
 Different tests are run to confirm or reject the hypotheses.
 Fixing the Issue:
 Once the issue is found, the code is modified to fix the error.
 Retesting:
 After the fix, the unit is retested to ensure the error is resolved and no new
issues have been introduced.
Extreme Programming (XP) and Unit Testing

 In Extreme Programming (XP), a practice called Test-Driven


Development (TDD) is followed. In TDD, developers write unit
tests before they even write the code for a function or feature. The
process follows this cycle:
 Write a Test: Write a test for a small function or feature.
 Write Code: Write just enough code to pass the test.
 Run the Test: Run the test to check if the code works as expected.
 Refactor: Clean up the code, and repeat the cycle.
 TDD helps developers focus on writing only the necessary code and
ensures each function performs as expected. It also helps improve code
quality and reduces unnecessary complexity.
JUnit Framework

 JUnit is a popular unit testing framework for Java. It provides a


structured way to write and run tests for Java applications. With
JUnit, developers can create test cases, make assertions, and run
automated tests. Some of its useful methods include:
 assertEquals(expected, actual): Checks if the expected result
matches the actual output.
 assertTrue(condition): Verifies that a condition is true.
 Example of JUnit Usage:
JUnit allows tests to be run
automatically, making it easier
to catch bugs early and continuously
verify that the code works as expected.
Tools for Unit Testing
There are several tools that help make unit testing more effective:
 Code Auditors: Ensure that the code follows best practices.
 Memory Leak Detectors: Identify areas of the code where
memory is not properly released.
 Interactive Debuggers: Allow developers to step through the
code to identify where problems occur.
 Test Coverage Analyzers: Measure how much of the code is
covered by tests.
 Performance Monitors: Track the performance of the
software to ensure it runs efficiently.
Mutation Testing

 Mutation testing is a technique used to evaluate the


effectiveness of unit tests. In mutation testing, small changes
(mutations) are introduced into the code to see if the tests
can detect the change. If the tests fail to identify the
mutation, it suggests that the test cases need to be improved.
Mutation testing helps ensure that the unit tests are robust
and can catch various types of errors.

You might also like