Unit 3-SWE
Unit 3-SWE
Quality control attempts to build a product, test it for expected behavior after it is built, and if the
expected behavior is not the same as the actual behavior of the product, fixes the product as is necessary and
rebuilds the product. This iteration is repeated till the expected behavior of the product matches the actual
behavior for the scenarios tested. Thus quality control is defect-detection and defect-correction oriented, and
works on the product rather than on the process.
Quality assurance, on the other hand, attempts defect prevention by concentrating on the process of
producing the product rather than working on defect detection / correction after the product is built. For
example, instead of producing and then testing a program code for proper behavior by exercising the built
product, a quality assurance approach would be to first review the design before the product is built and
correct the design errors in the first place.
Similarly, to ensure the production of a better code, a quality assurance process may mandate coding
standards to be followed by all programmers. Also, since quality assurance continues throughout the life of
the product it is everybody’s responsibility; hence it is a staff function. In contrast, the responsibility for
quality control is usually localized to a quality control team.
Verification Validation
It can find the bugs in the early stage of It can only find the bugs that could not
Bug the development. be found by the verification process.
It consists of checking of
It consists of execution of program and
Human or documents/files and is performed by
is performed by computer.
Computer human.
Error Focus Verification is for prevention of errors. Validation is for detection of errors.
Verification is also termed as white box Validation can be termed as black box
Another testing or static testing as work product testing or dynamic testing as work
Terminology goes through reviews. product is executed.
Verification Validation
Verification finds about 50 to 60% of the Validation finds about 20 to 30% of the
Performance defects. defects.
White box testing is a way of testing the external functionality of the code by examining and testing the
program code that realizes the external functionality. This is also known as clear box or glass box or open
box testing.
White box testing takes into account the program code, code structure and internal design flow. A number of
defects come about because of incorrect translation of requirements and design into program code. Some
other defects are created by programming errors and programming language idiosyncrasies. Since the
program code represents what the product actually does, testing by looking at the program code makes us
get closer to what the product is actually doing.
White box testing can be done for different purposes. The three main types are:
1. Unit Testing
2. Integration Testing
3. Regression Testing
Unit Testing
Checks if each part or function of the application works correctly.
Ensures the application meets design requirements during development.
Integration Testing
Examines how different parts of the application work together.
Done after unit testing to make sure components work well both alone and together.
Regression Testing
Verifies that changes or updates don’t break existing functionality.
Ensures the application still passes all existing tests after updates.
Static Testing
Static testing is a type of testing which requires only the source code of the product, not the binaries or
executables. Static testing does not involve executing the programs on computers but involves select people
going through the code to find out whether
the code works according to the functional requirement;
the code has been written in accordance with the design developed earlier in the project life cycle;
the code for any functionality has been missed out;
the code handles errors properly
There are multiple methods to achieve static testing by humans. They are as follows:
1. Desk checking of the code
2. Code walkthrough
3. Code review
4. Code inspection
Static testing by humans is done before the code is compiled and executed, some of these methods can be
viewed as process-oriented or defect prevention-oriented or quality assurance-oriented activities rather than
pure testing activities.
Desk Checking
Desk checking is a method to verify the portions of the code for correctness. Such verification is done by
comparing the code with the design or specifications to make sure that the code does what it is supposed to
do and effectively. This is the desk checking that most programmers do before compiling and executing the
code.
This method of catching and correcting errors is characterized by:
(i) No structured method or formalism to ensure completeness
(ii) No maintaining of a log or checklist
Advantages:
This method is that the programmer who knows the code and the programming language very well is
well equipped to read and understand his or her own code
The defects are detected and corrected with minimum time delay
Some of the disadvantages of this method of testing are as follows:
A developer is not the best person to detect problems in his or her own code. He or she may be
tunnel vision and have blind spots to certain types of problems.
Developers generally prefer to write new code rather than do any form of testing
This method is essentially person-dependent and informal and thus may not work consistently across
all developers
Code Walkthrough
This method and formal inspection are group-oriented methods. Walkthroughs are less formal than
inspections. The advantage that walkthrough has over desk checking is that it brings multiple perspectives.
Formal inspection
Code inspection – also called Fagan Inspection is a method, normally with a high degree of formalism. The
focus of this method is to detect all faults, violations and other side-effects. This method increases the
number of defects detected by
1. Demanding thorough preparation before an inspection / review
2. Enlisting multiple diverse views
3. Assigning specific roles to the multiple participants
4. Going sequentially through the code in a structured manner
Structural Testing
Structural testing takes into account the code, code structure, internal design and how they are coded.
The fundamental difference between structural testing and static testing is that in structural testing tests are
actually run by the computer on the built product, whereas in static testing, the product is tested by humans
using just the source code and not the executables or binaries.
Structural testing entails running the actual product against some pre-designed test cases to exercise as much
of the code as possible or necessary. A given portion of the code is exercised if a test case causes the
program to execute that portion of the code when running the test.
6.1. Unit / Code Functional Testing
This initial part of structural testing corresponds to some quick checks that a developer performs before
subjecting the code to more extensive code coverage testing or code complexity testing.
The developer can perform certain obvious tests, knowing the input variables and the corresponding
expected output variables. This can be a quick test that checks out any obvious mistakes. The review
mechanism does not waste time catching obvious errors.
For modules with complex logic or conditions, the developer can build a “debug version” of the
product by putting intermediate print statements and making sure the program is passing through the
right loops and iterations the right number of times.
Initial test is to run the product under a debugger or an Integrated Development Environment (IDE).
These tools allow single stepping of instruction, setting break points at any function or instruction
and viewing the various system parameters or program variable values.
All the above fall more under the “debugging” category of activities than under the “testing” category of
activities.
Statement coverage refers to writing test cases that execute each of the program statements. For a section of
code that consists of statements that are sequentially executed, test cases can be designed to run through
from top to bottom. First, if there are asynchronous exceptions that the code encounters, then, even if we
start a test case at the beginning of a section, the test case may not cover all the statements in that section.
Second a section of code may be entered from multiple points.
When we consider a two-way decision construct like the if statement, then to cover all the statements, we
should also cover the then and else parts of the if statement. This means we should have, for each if then
else, one test case to test the Then part and one test case to test the else part.
The multi-way decision construct such as a Switch statement can be reduced to multiple two-way if
statements. Thus, to cover all possible switch cases, there would be multiple tst cases.
Loop constructs present more variations to take care of. A loop-in various forms such as for, while, repeat
and so on – is characterized by executing a set of statements repeatedly until or while certain conditions are
met. One of the common looping errors is that the termination condition of the loops is not properly stated.
There is better statement coverage for statements within a loop, there should be test cases that,
1. Skip the loop completely, so that the situation of the termination condition being true before starting
the loop is tested.
2. Exercise the loop between once and the maximum number of times, to check all possible “normal”
operations of the loop.
3. Try covering the loop, around the “boundary” of n-that is, just below n, n, and just above n.
[ Statement Coverage = (Total statements exercised / Total number of executable statements in
program) * 100 ]
6.2.2 Path Coverage
In path coverage, we split a program into a number of distinct paths. A program can start from the beginning
and take any of the paths to its completion.
[ Path Coverage = (Total paths exercised / Total number of paths in program) * 100 ]
Path coverage provides a stronger condition of coverage than statement coverage as it relates to the various
logical paths in the program rather than just program statements.
6.2.3 Condition Coverage
The condition coverage, as defined by the formula alongside in the margin gives an indication of the
percentage of conditions covered by a set of test cases. Condition coverage is a much stronger criteria than
path coverage, which in turn is a much stronger criteria than statement coverage.
[ Condition Coverage = (Total decisions exercised / Total number of decisions in program) * 100 ]
6.2.4 Function Coverage
This is a new addition to structural testing to identify how many program functions are covered by test
cases.
The requirements of a product are mapped into functions during the design phase and each of the functions
form a logical unit. The advantages that function coverage provides over the other types of coverage are as
follows:
(i) Functions are easier to identify in a program and hence it is easier to write test cases to provide
function coverage
(ii) Since functions are at a much higher level of abstraction than code, it is easier to achieve 100
percent function coverage than 100 percent coverage in any of the earlier methods.
(iii) Functions have a more logical mapping to requirements and hence can provide a more direct
correlation to the test coverage of the product.
(iv) Functions are a means of realizing requirements, the importance of functions can be prioritized
based on the importance of the requirements they realize.
(v) Function coverage provides a natural transition to black box testing.
We can also measure how many time a given function is called. This will indicate which functions are used
most often and hence these functions become the target of any performance testing and optimization.
[Function Coverage = (Total functions exercised / Total number of functions in program) * 100]
1. Thorough Testing : White box testing is thorough as the entire code and structures are tested.
2. Code Optimization: It results in the optimization of code removing errors and helps in removing extra
lines of code.
3. Early Detection of Defects: It can start at an earlier stage as it doesn’t require any interface as in the
case of black box testing.
4. Integration with SDLC: White box testing can be easily started in Software Development Life Cycle.
5. Detection of Complex Defects: Testers can identify defects that cannot be detected through other
testing techniques.
6. Comprehensive Test Cases: Testers can create more comprehensive and effective test cases that cover
all code paths.
7. Testers can ensure that the code meets coding standards and is optimized for performance.
1. Programming Knowledge and Source Code Access: Testers need to have programming knowledge
and access to the source code to perform tests.
2. Overemphasis on Internal Workings: Testers may focus too much on the internal workings of the
software and may miss external issues.
3. Bias in Testing: Testers may have a biased view of the software since they are familiar with its internal
workings.
4. Test Case Overhead: Redesigning code and rewriting code needs test cases to be written again.
5. Dependency on Tester Expertise: Testers are required to have in-depth knowledge of the code and
programming language as opposed to black-box testing.
6. Inability to Detect Missing Functionalities: Missing functionalities cannot be detected as the code that
exists is tested.
7. Increased Production Errors: High chances of errors in production.
Functional Testing
Functional testing is defined as a type of testing that verifies that each function of the software
application works in conformance with the requirement and specification.
This testing is not concerned with the source code of the application. Each functionality of the software
application is tested by providing appropriate test input, expecting the output, and comparing the actual
output with the expected output.
This testing focuses on checking the user interface, APIs, database, security, client or server application,
and functionality of the Application Under Test. Functional testing can be manual or automated. It
determines the system’s software functional requirements.
Regression Testing
Regression Testing is the process of testing the modified parts of the code and the parts that might get
affected due to the modifications to ensure that no new errors have been introduced in the software after
the modifications have been made.
Regression means the return of something and in the software field, it refers to the return of a bug. It
ensures that the newly added code is compatible with the existing code.
In other words, a new software update has no impact on the functionality of the software. This is carried
out after a system maintenance operation and upgrades.
Nonfunctional Testing
Non-functional testing is a software testing technique that checks the non-functional attributes of the
system.
Non-functional testing is defined as a type of software testing to check non-functional aspects of a
software application.
It is designed to test the readiness of a system as per nonfunctional parameters which are never
addressed by functional testing.
Non-functional testing is as important as functional testing.
Non-functional testing is also known as NFT. This testing is not functional testing of software. It focuses
on the software’s performance, usability, and scalability.
Why black box testing
Black box testing helps in the overall functionality verification of the system under test. It is done based
on requirements. Black box testing addresses the stated requirements as well as implied requirements. It
encompasses the end user perspectives. It handles valid and invalid inputs.
When to do black box testing?
Black box testing activities require involvement of the testing team from the beginning of the software
project life cycle, regardless of the software development life cycle model chosen for the project.
How to do black box testing?
Black box testing exploits specifications to generate test cases in a methodical way to avoid
redundancy and to provide better coverage.
The various techniques we will discuss are as follows.
1. Requirements based testing
2. Positive and negative testing
3. Boundary value analysis
4. Decision tables
5. Equivalence partitioning
6. State based testing
7. Compatibility testing
8. User documentation testing
9. Domain testing
Positive Testing:
Positive Testing is testing process where the system validated against the valid input data. In this
testing tester always check for only valid set of values and check if a application behaves as
expected with its expected inputs.
Positive Testing always tries to prove that a given product and project always meets the
requirements and specifications. Under Positive testing is test the normal day to day life scenarios
and check the expected behavior of application.
Negative Testing:
Negative Testing is testing process where the system validated against the invalid input data.
A negative test checks if a application behaves as expected with its negative inputs.
The main intention of this testing is to check whether software application not showing error when
supposed to & showing error when not supposed to. Such testing is to be carried out keeping
negative point of view & only execute the test cases for only invalid set of input data.
Negative testing is a testing process to identify the inputs where system is not designed or un-
handled inputs by providing different invalid.
The main reason behind Negative testing is to check the stability of the software application against
the influences of different variety of incorrect validation data set.
Decision Table
A Decision Table Testing is a good way to deal with different combination of inputs which produce
different results. It is also called Cause-Effect Table. It provides a systematic way of stating complex
business rules, which is useful for developers as well as for testers. Decision tables can be used in test design
as they help testers to explore the effects of combinations of different inputs.
A decision table is basically an outstanding technique used in both testing and requirements management. It
is a structured exercise to prepare requirements when dealing with complex business rules..
Compatibility Testing
Compatibility testing is a non-functional testing conducted on the application to evaluate the application's
compatibility within different environments. It can be of two types - forward compatibility testing and
backward compatibility testing.
Operating system Compatibility Testing - Linux , Mac OS, Windows
Database Compatibility Testing - Oracle SQL Server
Browser Compatibility Testing - IE , Chrome, Firefox
Other System Software - Web server, networking/ messaging tool, etc.
Domain Testing
Domain testing is a software testing technique in which selecting a small number of test cases from a nearly
infinite group of test cases. For testing few applications, Domain specific knowledge plays a very crucial
role.
Domain testing is a type of functional testing and tests the application by feeding interesting inputs and
evaluating its outputs.
Domain - Equivalence Class Testing
Equivalence class carries its own significance when performing domain testing. Different ways of
equivalence class are:
Intuitive equivalence
Specified equivalence
Subjective equivalence
Risk-based equivalence
The tester does not need to have more functional knowledge or programming skills to implement the
Black Box Testing.
It is efficient for implementing the tests in the larger system.
Tests are executed from the user’s or client’s point of view.
Test cases are easily reproducible.
It is used to find the ambiguity and contradictions in the functional specifications.
There is a possibility of repeating the same tests while implementing the testing process.
Without clear functional specifications, test cases are difficult to implement.
It is difficult to execute the test cases because of complex inputs at different stages of testing.
Sometimes, the reason for the test failure cannot be detected.
Some programs in the application are not tested.
It does not reveal the errors in the control structure.
Working with a large sample space of inputs can be exhaustive and consumes a lot of time.
Black box testing uses methods White box testing uses methods
like equivalence partitioning , boundary like control flow testing , data flow
value analysis , and error guessing to testing and statement coverage
Testing methods create test cases. testing .
Black box testing is generally used for White box testing is used for testing
testing the software at the functional the software at the unit level,
Scope level. integration level and system level.
Black Box Testing is mostly done by White Box Testing is mostly done by
software testers. software developers.
Done By
Black Box Testing can be referred to as White Box Testing is the inner or the
outer or external software testing. internal software testing.
Terminology
Black Box Testing White Box Testing
Parameters
Black Box Testing is a functional test of White Box Testing is a structural test
the software. of the software.
Testing Level
Black Box Testing is the behavior testing White Box Testing is the logic testing
of the software. of the software.
Testing Focus
Black Box Testing is also called closed White Box Testing is also called as
Alternative testing. clear box testing.
Names
Black Box Testing is least time White Box Testing is most time
Time consuming. consuming.
Consumption
Suitable for Black Box Testing is not suitable or White Box Testing is suitable for
Algorithm preferred for algorithm testing. algorithm testing.
Testing
Objective The objective is to prevent defects. The objective is to find and fix defects.
Stage of It is performed at the early stage of It is performed at the later stage of the
execution software development. software development.
In static testing, the whole code is not In dynamic testing, the whole code is
Code Execution executed. executed.
Before/ After Static testing is performed before code Dynamic testing is performed after code
Code Deployment deployment. deployment.
Documents Static Testing involves a checklist for Dynamic Testing involves test cases for
Required the testing process. the testing process.
Cyclomatic Complexity
Cyclomatic complexity, developed by Thomas McCabe, is a metric that measures the complexity of a
program by counting its decision points. It measures the number of unique paths through the code,
indicating how complex the logic is. Lower complexity suggests simpler, more manageable code,
reducing the chances of errors and making it easier to maintain and modify. Essentially, it helps assess
the code’s readability and risk associated with changes.
M=E–N+2
where
E = the number of edges in the control flow graph
N = the number of nodes in the control flow graph
Steps that should be followed in calculating cyclomatic complexity and test cases design are:
Example
A = 10
IF B > C THEN
A=B
ELSE
A=C
ENDIF
Print A
Print B
Print C
Control Flow Graph of the above code:
The cyclomatic complexity calculated for the above code will be from the control flow graph.
The graph shows seven shapes(nodes), and seven lines(edges), hence cyclomatic complexity is
7-7+2 = 2.
A Control Flow Graph (CFG) is the graphical representation of control flow or computation during the
execution of programs or applications. Control flow graphs are mostly used in static analysis as well as
compiler applications, as they can accurately represent the flow inside a program unit. The control flow
graph was originally developed by Frances E. Allen..
3. do-while
4. for
Example
if A = 10 then
if B > C
A=B
else A = C
endif
endif
print A, B, C
Advantage of CFG
There are many advantages of a control flow graph.
1. It can easily encapsulate the information per each basic block.
2. It can easily locate inaccessible codes of a program and syntactic structures such as loops are easy to find
in a control flow graph.