Lecture 8
Lecture 8
Testing
Introduction to Software Engineering
Associate Professor
Hasan Abdulkader
COMPUTER SCIENCE AND TELECOMMUNICATIONS, PhD
Fall 2023-2024
1 2
• Software testing is a process in which you execute your program using • If the behaviour of the program does not match the behaviour that you
data that simulates user inputs. expect, then this means that there are bugs in your program that need to
be fixed.
• You observe its behaviour to see whether or not your program is doing
• There are two causes of program bugs:
what it is supposed to do.
• Programming errors You have accidentally included faults in your program
• Tests pass if the behaviour is what you expect. Tests fail if the behaviour differs
code. For example, a common programming error is an ‘off-by-1’ error where
from that expected.
you make a mistake with the upper bound of a sequence and fail to process the
last element in that sequence.
• If your program does what you expect, this shows that for the inputs used, the
program behaves correctly.
• Understanding errors You have misunderstood or have been unaware of
some of the details of what the program is supposed to do. For example, if your
• If these inputs are representative of a larger set of inputs, you can infer program processes data from a file, you may not be aware that some of this
that the program will behave correctly for all members of this larger input data is in the wrong format, so your program doesn’t include code to handle this.
set.
Testing & Devops Introduction to Software Engineering 3 Testing & Devops Introduction to Software Engineering 4
3 4
2023-12-28
Types of testing
Functional testing
Functional testing
Test the functionality of the overall system. The goals of functional testing are to • Functional testing involves developing a large set of program tests so
discover as many bugs as possible in the implementation of the system and to provide
convincing evidence that the system is fit for its intended purpose.
that, ideally, all of a program’s code is executed at least once.
User testing • The number of tests needed obviously depends on the size and the
Test that the software product is useful to and usable by end-users. You need to show functionality of the application.
that the features of the system help users do what they want to do with the software.
You should also show that users understand how to access the software’s features • For a business-focused web application, you may have to develop thousands of
and can use these features effectively. tests to convince yourself that your product is ready for release to customers.
Performance and load testing
Test that the software works quickly and can handle the expected load placed on the • Functional testing is a staged activity in which you initially test individual
system by its users. You need to show that the response and processing time of your units of code. You integrate code units with other units to create larger
system is acceptable to end-users. You also need to demonstrate that your system units then do more testing.
can handle different loads and scales gracefully as the load on the software increases.
• The process continues until you have created a complete system ready for
Security testing release.
Test that the software maintains its integrity and can protect user information from theft
and damage.
Testing & DevOps Introduction to Software Engineering 5 Testing & Devops Introduction to Software Engineering 6
5 6
Unit testing
The aim of unit testing is to test program units in isolation. Tests should be designed to execute
all of the code in a unit at least once. Individual code units are tested by the programmer as
they are developed.
Feature testing
Code units are integrated to create features. Feature tests should test all aspects of a feature.
All of the programmers who contribute code units to a feature should be involved in its testing.
System testing
Code units are integrated to create a working (perhaps incomplete) version of a system. The
aim of system testing is to check that there are no unexpected interactions between the
features in the system. System testing may also involve checking the responsiveness, reliability
and security of the system. In large companies, a dedicated testing team may be responsible
for system testing. In small companies, this is impractical, so product developers are also
involved in system testing.
Release testing
The system is packaged for release to customers and the release is tested to check that it
operates as expected. The software may be released as a cloud service or as a download to be
installed on a customer’s computer or mobile device. If DevOps is used, then the development
team are responsible for release testing otherwise a separate team has that responsibility.
Testing & DevOps Introduction to Software Engineering 7 Testing & DevOps Introduction to Software Engineering 8
7 8
2023-12-28
• As you develop a code unit, you should also develop tests for that code.
• If a program unit behaves as expected for a set of inputs that have some shared
characteristics, it will behave in the same way for a larger set whose members
share these characteristics.
• The equivalence partitions that you identify should not just include those
containing inputs that produce the correct values. You should also identify
‘incorrectness partitions’ where the inputs are deliberately incorrect.
Testing & Devops Introduction to Software Engineering 9 Testing & DevOps Introduction to Software Engineering 10
9 10
One is different
If your program deals with sequences, always test with sequences that have a
single value.
Testing & DevOps Introduction to Software Engineering 11 Testing & DevOps Introduction to Software Engineering 12
11 12
2023-12-28
• Features have to be tested to show that the functionality is implemented • Interaction tests
as expected and that the functionality meets the real needs of users. • These test the interactions between the units that implement the feature. The developers of the
units that are combined to make up the feature may have different understandings of what is
• For example, if your product has a feature that allows users to login using their required of that feature.
Google account, then you have to check that this registers the user correctly
and informs them of what information will be shared with Google. • The integration may also reveal bugs in program units, which were not exposed by unit testing.
• Usefulness tests
• Normally, a feature that does several things is implemented by multiple,
interacting, program units. • These test that the feature implements what users are likely to want.
• For example, the developers of a login with Google feature may have implemented an opt-out
• These units may be implemented by different developers and all of these default on registration so that users receive all emails from a company. They must expressly
developers should be involved in the feature testing process. choose what type of emails that they don’t want.
Testing & Devops Introduction to Software Engineering 13 Testing & Devops Introduction to Software Engineering 14
13 14
• System testing involves testing the system as a whole, rather than the • Release testing is a type of system testing where a system that’s intended for
individual system features. release to customers is tested.
• The fundamental differences between release testing and system testing are:
• System testing should focus on four things:
• Release testing tests the system in its real operational environment rather than in a
• Testing to discover if there are unexpected and unwanted interactions between test environment. Problems commonly arise with real user data, which is sometimes
the features in a system. more complex and less reliable than test data.
• Testing to discover if the system features work together effectively to support • The aim of release testing is to decide if the system is good enough to release, not to
what users really want to do with the system. detect bugs in the system. Therefore, some tests that ‘fail’ may be ignored if these
have minimal consequences for most users.
• Testing the system to make sure it operates in the expected way in the different
environments where it will be used. • Preparing a system for release involves packaging that system for
deployment (e.g. in a container if it is a cloud service) and installing software
• Testing the responsiveness, throughput, security and other quality attributes of and libraries that are used by your product. You must define configuration
the system. parameters such as the name of a root directory, the database size limit per
user and so on.
Testing & Devops Introduction to Software Engineering 15 Testing & Devops Introduction to Software Engineering 16
15 16
2023-12-28
• An executable test includes the input data to the unit that is being tested,
the expected result and a check that the unit returns the expected result.
• You run the test and the test passes if the unit returns the expected
result.
Testing & Devops Introduction to Software Engineering 17 Testing & DevOps Introduction to Software Engineering 18
17 18
Testing & DevOps Introduction to Software Engineering 19 Testing & Devops Introduction to Software Engineering 20
19 20
2023-12-28
• System testing, which should follow feature testing, involves testing the
system as a surrogate user.
• You are looking for interactions between features that cause problems,
sequences of actions that lead to system crashes and so on.
Testing & Devops Introduction to Software Engineering 21 Testing & DevOps Introduction to Software Engineering 22
21 22
Testing & Devops Introduction to Software Engineering 23 Testing & DevOps Introduction to Software Engineering 24
23 24
2023-12-28
Testing & DevOps Introduction to Software Engineering 25 Testing & DevOps Introduction to Software Engineering 26
25 26
• It is a systematic approach to testing in which tests are clearly linked to • TDD discourages radical program change
sections of the program code. I found that I was reluctant to make refactoring decisions that I knew would cause many tests to
fail. I tended to avoid radical program change for this reason.
• This means you can be confident that your tests cover all of the code that has
• I focused on the tests rather than the problem I was trying to solve
been developed and that there are no untested code sections in the delivered
A basic principle of TDD is that your design should be driven by the tests you have written. I
code. In my view, this is the most significant benefit of TDD. found that I was unconsciously redefining the problem I was trying to solve to make it easier to
write tests. This meant that I sometimes didn’t implement important checks, because it was
• The tests act as a written specification for the program code. In principle difficult to write tests in advance of their implementation.
at least, it should be possible to understand what the program does by
reading the tests. • I spent too much time thinking about implementation details rather than the programming
problem
Sometimes when programming, it is best to step back and look at the program as a whole rather
• Debugging is simplified because, when a program failure is observed, you than focusing on implementation details. TDD encourages a focus on details that might cause
can immediately link this to the last increment of code that you added to tests to pass or fail and discourages large-scale program revisions.
the system.
• It is hard to write ‘bad data’ tests
• It is argued that TDD leads to simpler code as programmers only write Many problems involving dealing with messy and incomplete data. It is practically impossible to
code that’s necessary to pass tests. They don’t over-engineer their code anticipate all of the data problems that might arise and write tests for these in advance. You
might argue that you should simply reject bad data but this is sometimes impractical.
with complex features that aren’t needed.
Testing & Devops Introduction to Software Engineering 27 Testing & Devops Introduction to Software Engineering 28
27 28
2023-12-28
• Security testing aims to find vulnerabilities that may be exploited by an • A risk-based approach to security testing involves identifying common
attacker and to provide convincing evidence that the system is risks and developing tests to demonstrate that the system protects itself
sufficiently secure. from these risks.
• The tests should demonstrate that the system can resist attacks on its • You may also use automated tools that scan your system to check for
availability, attacks that try to inject malware and attacks that try to known vulnerabilities, such as unused HTTP ports being left open.
corrupt or steal users’ data and identity.
• Based on the risks that have been identified, you then design tests and
• Comprehensive security testing requires specialist knowledge of checks to see if the system is vulnerable.
software vulnerabilities and approaches to testing that can find these
vulnerabilities. • It may be possible to construct automated tests for some of these
checks, but others inevitably involve manual checking of the system’s
behaviour and its files.
• Once you have identified security risks, you then analyze them to assess
how they might arise.
Testing & Devops Introduction to Software Engineering 29 Testing & Devops Introduction to Software Engineering 30
29 30
• Code reviews involve one or more people examining the code to check
for errors and anomalies and discussing issues with the developer.
• Code reviews complement testing. They are effective in finding bugs that
arise through misunderstandings and bugs that may only arise when
unusual sequences of code are executed.
Testing & Devops Introduction to Software Engineering 31 Testing & DevOps Introduction to Software Engineering 32
31 32
2023-12-28
Testing & DevOps Introduction to Software Engineering 33 Testing & DevOps Introduction to Software Engineering 34
33 34
Software support
35 36
2023-12-28
• There are inevitable delays and overheads in the traditional support model.
• Agile software engineering reduced the development time for software, but the
traditional release process introduced a bottleneck between development and
deployment.
Testing & DevOps Introduction to Software Engineering 37 Testing & Devops Introduction to Software Engineering 38
37 38
Testing & DevOps Introduction to Software Engineering 39 Testing & DevOps Introduction to Software Engineering 40
39 40
2023-12-28
• During the development of a software product, the development team • Source code management, combined with automated system building, is
will probably create tens of thousands of lines of code and automated essential for professional software engineering.
tests.
• In companies that use DevOps, a modern code management system is a
• These will be organized into hundreds of files. Dozens of libraries may fundamental requirement for ‘automating everything’.
be used, and several, different programs may be involved in creating and
running the code. • Not only does it store the project code that is ultimately deployed, it also
stores all other information that is used in DevOps processes.
• Code management is a set of software-supported practices that is used
to manage an evolving codebase. • DevOps automation and measurement tools all interact with the code
management system
• You need code management to ensure that changes made by different
developers do not interfere with each other, and to create different
product versions.
Testing & Devops Introduction to Software Engineering 41 Testing & Devops Introduction to Software Engineering 42
41 42
• Code transfer Developers take code into their personal file store to work on it
then return it to the shared code management system.
• Version storage and retrieval Files may be stored in several different versions
and specific versions of these files can be retrieved.
Testing & DevOps Introduction to Software Engineering 43 Testing & Devops Introduction to Software Engineering 44
43 44
2023-12-28
Testing & Devops Introduction to Software Engineering 45 Testing & DevOps Introduction to Software Engineering 46
45 46
• Resilience
• Everyone working on a project has their own copy of the repository. If the shared
repository is damaged or subjected to a cyberattack, work can continue, and the
clones can be used to restore the shared repository. People can work offline if they
don’t have a network connection.
• Speed
• Committing changes to the repository is a fast, local operation and does not need data
to be transferred over the network.
• Flexibility
• Local experimentation is much simpler. Developers can safely experiment and try
different approaches without exposing these to other project members. With a
centralized system, this may only be possible by working outside the code
management system.
Testing & Devops Introduction to Software Engineering 47 Testing & DevOps Introduction to Software Engineering 48
47 48
2023-12-28
• Branching and merging are fundamental ideas that are supported by all
code management systems.
• The repository ensures that branch files that have been changed cannot
overwrite repository files without a merge operation.
• If Alice or Bob make mistakes on the branch they are working on, they can easily
revert to the master file.
• If they commit changes, while working, they can revert to earlier versions of the
work they have done. When they have finished and tested their code, they can then
replace the master file by merging the work they have done with the master branch
Testing & Devops Introduction to Software Engineering 49 Testing & DevOps Introduction to Software Engineering 50
49 50
Continuous integration
• By using DevOps with automated support, you can dramatically reduce Each time a developer commits a change to the project’s master branch, an
the time and costs for integration, deployment and delivery. executable version of the system is built and tested.
Continuous delivery
• Everything that can be, should be automated is a fundamental principle
A simulation of the product’s operating environment is created and the
of DevOps. executable software version is tested.
• As well as reducing the costs and time required for integration, Continuous deployment
deployment and delivery, process automation also makes these A new release of the system is made available to users every time a change is
processes more reliable and reproducible. made to the master branch of the software.
• Automation information is encoded in scripts and system models that Infrastructure as code
Machine-readable models of the infrastructure (network, servers, routers, etc.) on
can be checked, reviewed, versioned and stored in the project
which the product executes are used by configuration management tools to build
repository. the software’s execution platform. The software to be installed, such as compilers
and libraries and a DBMS, are included in the infrastructure model.
Testing & Devops Introduction to Software Engineering 51 Testing & DevOps Introduction to Software Engineering 52
51 52
2023-12-28
• System integration (system building) is the process of gathering all of the • Continuous integration simply means that an integrated version of the
elements required in a working system, moving them into the right directories, system is created and tested every time a change is pushed to the
and putting them together to create an operational system. system’s shared repository.
• Typical activities that are part of the system integration process include: • On completion of the push operation, the repository sends a message to
• Installing database software and setting up the database with the appropriate schema.
an integration server to build a new version of the product
• Loading test data into the database. • The advantage of continuous integration compared to less frequent
integration is that it is faster to find and fix bugs in the system.
• Compiling the files that make up the product.
• If you make a small change and some system tests then fail, the problem
• Linking the compiled code with the libraries and other components used.
almost certainly lies in the new code that you have pushed to the project
• Checking that external services used are operational. repo.
• Deleting old configuration files and moving configuration files to the correct locations. • You can focus on this code to find the bug that’s causing the problem.
• Running a set of system tests to check that the integration has been successful.
Testing & Devops Introduction to Software Engineering 53 Testing & Devops Introduction to Software Engineering 54
53 54
• Continuous integration is only effective if the integration process is fast • Continuous Integration • Continuous deployment
and developers do not have to wait for the results of their tests of the
integrated system. • Continuous integration means • However, the real environment in which
creating an executable version of software runs will inevitably be different
• However, some activities in the build process, such as populating a a software system whenever a from your development system. When
database or compiling hundreds of system files, are inherently slow. change is made to the your software runs in its real, operational
repository. The CI tool builds the environment bugs may be revealed that
• It is therefore essential to have an automated build process that system and runs tests on your did not show up in the test environment.
minimizes the time spent on these activities. development computer or project
integration server.
• Fast system building is achieved using a process of incremental building,
where only those parts of the system that have been changed are rebuilt • Continuous delivery means that, • This means that you have to test it in a
after making changes to a production environment to make sure
system, you ensure that the that environmental factors do not cause
changed system is ready for system failures or slow down its
delivery to customers. performance.
Testing & Devops Introduction to Software Engineering 55 Testing & Devops Introduction to Software Engineering 56
55 56
2023-12-28
• The aim of program testing is to find bugs and to show that a program does what
its developers expect it to do.
• Four types of testing that are relevant to software products are functional testing,
user testing, load and performance testing and security testing.
• Unit testing involves testing program units such as functions or class methods that
have a single responsibility. Feature testing focuses on testing individual system
features. System testing tests the system as a whole to check for unwanted
interactions between features and between the system and its environment.
• Identifying equivalence partitions, in which all inputs have the same characteristics,
and choosing test inputs at the boundaries of these partitions, is an effective way
of finding bugs in a program.
• Test automation is based on the idea that tests should be executable. You develop
a set of executable tests and run these each time you make a change to a system.
Testing & DevOps Introduction to Software Engineering 57 Testing & Devops Introduction to Software Engineering 58
57 58
• The structure of an automated unit test should be arrange-action-assert. • DevOps is the integration of software development and the management of
You set up the test parameters, call the function or method being tested, that software once it has been deployed for use. The same team is
and make an assertion of what should be true after the action has been responsible for development, deployment and software support.
completed. • The benefits of DevOps are faster deployment, reduced risk, faster repair of
buggy code and more productive teams.
• Test-driven development is an approach to development where executable
tests are written before the code. Code is then developed to pass the tests. • Source code management is essential to avoid changes made by different
developers interfering with each other.
• A disadvantage of test-driven development is that programmers focus on
the detail of passing tests rather than considering the broader structure of • All code management systems are based around a shared code repository
their code and algorithms used. with a set of features that support code transfer, version storage and
retrieval, branching and merging and maintaining version information.
• Security testing may be risk driven where a list of security risks is used to
• Git is a distributed code management system that is the most widely used
identify tests that may identify system vulnerabilities. system for software product development. Each developer works with their
own copy of the repository which may be merged with the shared project
• Code reviews are an effective supplement to testing. They involve people repository.
checking the code to comment on the code quality and to look for bugs.
Testing & Devops Introduction to Software Engineering 59 Testing & Devops Introduction to Software Engineering 60
59 60
2023-12-28
Key points 4
• Automated system building tools reduce the time needed to compile and integrate the
system by only recompiling those components and their dependents that have
changed.
• Measurement is a fundamental principle of DevOps. You may make both process and
product measurements. Important process metrics are deployment frequency,
percentage of failed deployments, and mean time to recovery from failure.
61