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

Unit Testing

The document discusses different types of software testing: - Unit testing tests individual units or components of software and validates that each performs as designed. It is typically done through white box testing at the function level. - Integration testing combines units and tests them as a group to expose faults in interaction between integrated units. - System testing tests complete integrated systems to evaluate compliance with specified requirements. - Acceptance testing evaluates system compliance with business requirements to assess if it is acceptable for delivery. The document then provides details on unit testing techniques like statement coverage, decision coverage, branch coverage, and condition coverage. It also discusses manual vs automated unit testing and tasks involved in unit testing.

Uploaded by

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

Unit Testing

The document discusses different types of software testing: - Unit testing tests individual units or components of software and validates that each performs as designed. It is typically done through white box testing at the function level. - Integration testing combines units and tests them as a group to expose faults in interaction between integrated units. - System testing tests complete integrated systems to evaluate compliance with specified requirements. - Acceptance testing evaluates system compliance with business requirements to assess if it is acceptable for delivery. The document then provides details on unit testing techniques like statement coverage, decision coverage, branch coverage, and condition coverage. It also discusses manual vs automated unit testing and tasks involved in unit testing.

Uploaded by

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

Unit testing is a level of software testing where individual units/ components of a software are

tested. The purpose is to validate that each unit of the software performs as designed. A unit is
the smallest testable part of any software. It usually has one or a few inputs and usually a single
output.

Acceptance Testing: A level of the software testing process where a system is tested for
acceptability. The purpose of this test is to evaluate the system’s compliance with the
business requirements and assess whether it is acceptable for delivery.

System Testing: A level of the software testing process where a complete, integrated
system/software is tested. The purpose of this test is to evaluate the system’s compliance with
the specified requirements.

Integration Testing: A level of the software testing process where individual units are
combined and tested as a group. The purpose of this level of testing is to expose faults in the
interaction between integrated units.

Unit Testing: A level of the software testing process where individual units/components of a
software/system are tested. The purpose is to validate that each unit of the software performs
as designed.

Unit Testing is the first level of software testing and is performed prior to Integration Testing.

Unit Testing Method :


It is performed by using the White Box Testing method.
This is a white box testing at function level. The function is considering a lowest unit of the
source code for unit testing. Any new function or modified function has to be tested at unit
level (with debug environment is better) while looking into the internal behaviour after
executing each statement in the source code. The scope of this testing include Boundary value
test, Branch test, Loop test, and parameter test within the function.

 Unit Test cases should be independent. In case of any enhancements or change in


requirements, unit test cases should not be affected.
 In case of a change in code in any module, ensure there is a corresponding unitTest
Case for the module, and the module passes the tests before changing the
implementation

Unit Testing Tasks

 Unit Test Plan


o Prepare
o Review
o Rework
o Baseline
 Unit Test Cases/Scripts
o Prepare
o Review
o Rework
o Baseline
 Unit Test
o Perform

Unit Testing is of two types

 Manual
 Automated

Unit testing is commonly automated but may still be performed manually. Software
Engineering does not favour one over the other but automation is preferred. A manual approach
to unit testing may employ a step-by-step instructional document.

Unit Testing Techniques

Code coverage techniques used in united testing are listed below:

 Statement Coverage
 Decision Coverage
 Branch Coverage
 Condition Coverage
 Finite State Machine Coverage

Statement Coverage

Statement coverage is a white box test design technique which involves execution of all the
executable statements in the source code at least once. It is used to calculate and measure the
number of statements in the source code which can be executed given the requirements.

Statement coverage is used to derive scenario based upon the structure of the code under test.
In White Box Testing, the tester is concentrating on how the software works. In other words,
the tester will be concentrating on the internal working of source code concerning control
flow graphs or flow charts.

Generally in any software, if we look at the source code, there will be a wide variety of
elements like operators, functions, looping, exceptional handlers, etc. Based on the input to
the program, some of the code statements may not be executed. The goal of Statement
coverage is to cover all the possible path's, line, and statement in the code.

Let's understand this with an example, how to calculate statement coverage.

Scenario to calculate Statement Coverage for given source code. Here we are taking two
different scenarios to check the percentage of statement coverage for each scenario.

Example of statement coverage

Source Code:

Prints (int a, int b) { ------------ Printsum is a function


int result = a+ b;
If (result> 0)
Print ("Positive", result)
Else
Print ("Negative", result)
} ----------- End of the source code

Scenario 1:

If A = 3, B = 9

The statements marked in yellow color are those which are executed as per the scenario

Number of executed statements = 5, Total number of statements = 7

Statement Coverage: 5/7 = 71%


Likewise we will see scenario 2,

Scenario 2:

If A = -3, B = -9

The statements marked in yellow color are those which are executed as per the scenario.

Number of executed statements = 6

Total number of statements = 7

Statement Coverage: 6/7 = 85%

But overall if you see, all the statements are being covered by 2nd scenario's considered. So
we can conclude that overall statement coverage is 100%.

What is covered by Statement Coverage?

1. Unused Statements
2. Dead Code
3. Unused Branches
Decision Coverage

Decision coverage reports the true or false outcomes of each Boolean expression. In this
coverage, expressions can sometimes get complicated. Therefore, it is very hard to achieve
100% coverage.

That's why there are many different methods of reporting this metric. All these methods focus
on covering the most important combinations. It is very much similar to decision coverage,
but it offers better sensitivity to control flow.

Example of decision coverage

Consider the following code-

Demo(int a) {
If (a> 5)
a=a*3
Print (a)
}

Scenario 1:

Value of a is 2

The code highlighted in yellow will be executed. Here the "No" outcome of the decision If
(a>5) is checked.

Decision Coverage = 50%

Scenario 2:

Value of a is 6
The code highlighted in yellow will be executed. Here the "Yes" outcome of the decision If
(a>5) is checked.

Decision Coverage = 50%

Test Case Value of A Output Decision Coverage

1 2 2 50%

2 6 18 50%

Branch Coverage

In the branch coverage, every outcome from a code module is tested. For example, if the
outcomes are binary, you need to test both True and False outcomes.

It helps you to ensure that every possible branch from each decision condition is executed at
least a single time.

By using Branch coverage method, you can also measure the fraction of independent code
segments. It also helps you to find out which is sections of code don't have any branches.

The formula to calculate Branch Coverage:

Example of Branch Coverage

To learn branch coverage, let's consider the same example used earlier

Consider the following code

Demo(int a) {
If (a> 5)
a=a*3
Print (a)
}

Branch Coverage will consider unconditional branch as well

Test Case Value of A Output Decision Coverage

1 2 2 50%

2 6 18 50%

Advantages of Branch coverage:

Branch coverage Testing offers the following advantages:

 Allows you to validate-all the branches in the code


 Helps you to ensure that no branched lead to any abnormality of the program's
operation
 Branch coverage method removes issues which happen because of statement coverage
testing
 Allows you to find those areas which are not tested by other testing methods
 It allows you to find a quantitative measure of code coverage
 Branch coverage ignores branches inside the Boolean expressions

Condition Coverage

Conditional coverage or expression coverage will reveal how the variables or subexpressions
in the conditional statement are evaluated. In this coverage expressions with logical operands
are only considered.

For example, if an expression has Boolean operations like AND, OR, XOR, which indicated
total possibilities.
Conditional coverage offers better sensitivity to the control flow than decision coverage.
Condition coverage does not give a guarantee about full decision coverage

The formula to calculate Condition Coverage:

Example of Condition Coverage

For the above expression, we have 4 possible combinations

 TT
 FF
 TF
 FT

Consider the following input

X=3 (x<y) TRUE Condition Coverage is ¼ = 25%

Y=4

A=3 (a>b) FALSE

B=4

Unit tests help with code re-use. Migrate both your code and your tests to your new project.
Tweak the code till the tests run again.

Conformance Testing (Compliance Testing):

Conformance Testing is defined as a software testing type that determines whether the system
complies with requirements of specifications and conditions, regulations and standards, etc.
along with its documentation. It is also called as Compliance Testing.

Why do we need Conformance Testing?

 To check for the system's requirements fulfillment


 To check whether the system documentation is complete with needful
 To check the development, design and evaluation as per specifications
What do we need to test?

 The standards through which the implementation takes place


 The call of the system that is to be developed
 Scope of specifications
 Specification objectives

Conformance Testing is initiated by the management with total assurance about the team and
their understanding of standards, specifications, and procedures.

What is Performance Testing?

Performance Testing is defined as a type of software testing to ensure software applications


will perform well under their expected workload.

Features and Functionality supported by a software system is not the only concern. A
software application's performance like its response time, reliability, resource usage and
scalability do matter. The goal of Performance Testing is not to find bugs but to eliminate
performance bottlenecks.

The focus of Performance Testing is checking a software program's

 Speed - Determines whether the application responds quickly


 Scalability - Determines maximum user load the software application can handle.
 Stability - Determines if the application is stable under varying loads

Performance Testing is done to provide stakeholders with information about their application
regarding speed, stability, and scalability. More importantly, Performance Testing uncovers
what needs to be improved before the product goes to market. Without Performance Testing,
software is likely to suffer from issues such as: running slow while several users use it
simultaneously, inconsistencies across different operating systems and poor usability.

What is Interface Testing?

Interface Testing is defined as a software testing type which verifies whether the
communication between two different software systems is done correctly.

An interface is actually software that consists of sets of commands, messages, and other
attributes that enable communication between a device and a user.

How to do Interface Testing

Interface Testing includes testing of two main segments:

1. Web server and application server interface


2. Application server and Database server interface.
Why do Interface Testing

Interface Testing is done

 To ensure that end-users or customer should not encounter any problem when using a
particular software product
 To identify which application areas are usually accessed by end-users and to check its
user-friendliness as well.
 To verify security requirements while communication propagates between the
systems
 To check if a solution is capable to handle network failures between an application
server and website

What is Functional Testing?

Functional Testing is defined as a type of testing which verifies that each function of the
software application operates in conformance with the requirement specification. This testing
mainly involves black box testing and it is not concerned about the source code of the
application.

Each and every functionality of the system is tested by providing appropriate input, verifying
the output and comparing the actual results with the expected results.

What do you test in Functional Testing?

The prime objective of Functional testing is checking the functionalities of the software
system. It mainly concentrates on -

 Mainline functions: Testing the main functions of an application


 Basic Usability: It involves basic usability testing of the system. It checks whether a
user can freely navigate through the screens without any difficulties.
 Accessibility: Checks the accessibility of the system for the user
 Error Conditions: Usage of testing techniques to check for error conditions. It
checks whether suitable error messages are displayed.

You might also like