0% found this document useful (0 votes)
30 views22 pages

Unit Testing: Done By: Harini.D 1732J08

Unit testing is the testing of individual software components or units of code. It is done early in the development process by developers to validate that each unit of code performs as expected. Some key techniques for unit testing include white box, black box, and grey box testing. Automated unit testing tools like JUnit and TestNG help test code functionality and reduce debugging time by automatically generating test results. Unit testing finds defects early and helps improve code quality and reusability.

Uploaded by

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

Unit Testing: Done By: Harini.D 1732J08

Unit testing is the testing of individual software components or units of code. It is done early in the development process by developers to validate that each unit of code performs as expected. Some key techniques for unit testing include white box, black box, and grey box testing. Automated unit testing tools like JUnit and TestNG help test code functionality and reduce debugging time by automatically generating test results. Unit testing finds defects early and helps improve code quality and reusability.

Uploaded by

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

UNIT TESTING

DONE BY:
HARINI.D
1732J08
SYNOPSIS:
• INTRODUCTION
• UNIT TESTING
• CRUCIAL REASONS FOR UNIT TESTING
• UNIT TESTING TECHNIQUES
• OTHER UNIT TESTING TECHNIQUES
• UNIT TESTING METHODS
• UNIT TESTING TOOLS
• EXAMPLE
• HOW TO ACHIEVE THE BEST RESULTS VIA UNIT TESTING?
• ADVANTAGES AND DISADVANTAGES OF UNIT TESTING
• CONCLUSION
INTRODUCTION:

• A unit is a single testable part of a software system and tested during the
development phase of the application software.

• A unit component is an individual function or code of the application. White box


testing approach used for unit testing and usually done by the developers.

• Whenever the application is ready and given to the Test engineer, he/she will start
checking every component of the module or module of the application
independently or one by one, and this process is known as Unit
testing or components testing.
UNIT TESTING:
• Unit testing is the testing of each unit or an individual component of the software application.

• It is the first level of functional testing.

• The aim behind unit testing is to validate unit components with its performance.

• The purpose of unit testing is to test the correctness of isolated code.

• In a testing level hierarchy, unit testing is the first level of testing done before integration and other remaining levels of the
testing.

• It uses modules for the testing process which reduces the dependency of waiting for Unit testing frameworks, stubs, drivers
and mock objects are used for assistance in unit testing.

• The skipping of unit testing may lead to higher defects during Integration Testing, System Testing, and Acceptance Testing or
even during Beta Testing which takes place after the completion of software application.
CRUCIAL REASONS FOR USING
UNIT TESTING:

• Unit testing helps tester and developers to understand the base of code that makes
them able to change defect causing code quickly.

• Unit testing helps in the documentation.

• Unit testing fixes defects very early in the development phase that's why there is a
possibility to occur a smaller number of defects in upcoming testing levels.

• It helps with code reusability by migrating code and test cases.


UNIT TESTING TECHNIQUES:

WHITE BOX TESTING BLACK BOX TESTING GREY BOX TESTING


-- The tester does not know the -- The testers are only partially aware of the internal
-- The tester knows the internal structure of internal structures either the code of structure, functions, and designs along with the
the software including the code and can test the software. requirements.
it against the design and the requirements. -- Debugging is done by actual input from the front-end to
get exact data in the back-end.
-- It is therefore considered as a combination of black box
-- It is also known as transparent testing. and white box testing techniques.
-- This is also referred to as semi-transparent technique
testing 
OTHER UNIT TESTING TECHNIQUES INCLUDE:

WHITE BOX TESTING GREY BOX TESTING

• Data flow Testing • Matrix Testing.


• Control Flow Testing • Pattern Testing.
• Branch Coverage Testing • Orthogonal Pattern Testing.
• Statement Coverage Testing
• Regression Testing.
• Decision Coverage Testing
UNIT TESTING METHODS:
MANUAL METHOD AUTOMATED METHOD

• The tester manually executes test cases • Software testing automation tools are used to
without using any automation tool. automate the tests/test cases.
• Here, each stage of the test is executed • The automation tool can record and save
manually. It is tedious especially for tests your test and it can be re-played as many
that are repetitive and requires more times as needed without any further human
effort to create and execute test cases. intervention.
• It does not require knowledge of any • These tools can even enter test data into the
testing tool. system being tested as well as it can compare
the expected results to the actual results and
• It is a fact that 100% of Automation is not automatically generate the reports.
possible and thus there will always be • However, the initial cost of setting up test
some level of manual testing performed. automation tools is high.
UNIT TESTING TOOLS:
NUNIT: JUNIT:

• One of the most commonly used unit • It is another open-source unit testing
testing tools is NUnit. framework, which was written in Java
• It is an open-source tool and initially programing language.
ported from the JUnit, which works for • It is mainly used in the development of the
all .Net languages. test-driven environment.
• NUnit was written entirely in the C# • Junit offers the annotation, which helps us
language and fully redesigned to get the to find the test method.
advantage of many .Net language features. • This tool helps us to enhance the efficiency
• Like custom attributes and other reflection of the developer, which provides the
related capabilities. consistency of the development code and
reduces the time of the debugging.
TESTNG (TEST NEXT
MOCKITO: PHP UNIT:
GENERATION):
-- It is a mocking framework that is used in -- It was written in PHP programing
-- It is an open-source tool, which the unit testing, and it was written in the Java
supports Java and .Net programming language.
programing language.
languages. 
-- Mockito is also an open-source tool -- It is an instance of the xUnit
-- It is an advance unit testing tool, introduced by the MIT (Massachusetts architecture and based on the JUnit
which is stimulated from JUnit and Institute of Technology) License. framework.
NUnit testing frameworks.
-- With the help of Mockito, we can develop -- It can generate the test results output
-- Still, few new functionalities the testable application.
(Additional Annotation, Parallel in many various formats with JSON,
Execution, Group Execution, Html JUnit XML, TestDox, and Test
Report, and Listener) make a TestNG -- The primary objective of using this tool is anything protocol.
more powerful tool. to simplify the development of a test by
mocking external dependencies and use them
in the test code. --We can run the test cases on the
-- For the automation process, TestNG cross-platform operating system.
will be used to handle the framework
component and achieve the batch -- It can be used with other testing
execution without any human frameworks such as TestNG and Junit.
interference.
EXAMPLE
:
• For the amount transfer, requirements are as follows:
1. Amount transfer

1.1 From account number (FAN)→ Text Box

1.1.1 FAN→ accept only 4 digit

1.2 To account no (TAN)→ Text Box

1.2.1 TAN→ Accept only 4 digit

1.3 Amount→ Text Box

1.3.1 Amount → Accept maximum 4 digit

1.4 Transfer→ Button

1.4.1 Transfer → Enabled

1.5 Cancel→ Button

1.5.1 Cancel→ Enabled


Below are the application access details, which is given by the customer:

• URL→ login Page


• Username/password/OK → home page

To reach Amount transfer module follow the below:

LOANS → SALES → AMOUNT TRANSFER


RULES FOLLOWED DURING UNIT TESTING:

• To start unit testing, at least we should have one module.


• Test for positive values
• Test for negative values
• No over testing
• No assumption required
• When we feel that the maximum test coverage is achieved, we
will stop the testing.
Now, we will start performing the unit testing on the different components such
as
• From account number(FAN)
• To account number(TAN)
• Amount
• Transfer
• Cancel
• For the FAN components:

Values Description

1234 accept

4311 Error message→ account valid or not

blank Error message→ enter some values

5 digit/ 3 digit Error message→ accept only 4 digit

Alphanumeric Error message → accept only digit

Blocked account no Error message

Copy and paste the value Error message→ type the value

Same as FAN and TAN Error message


• For the TAN component:

Provide the values just like we did in From account number (FAN) components.

• For Amount component:

Provide the values just like we did in FAN and TAN components.

• For Transfer component:


-- Enter valid FAN value
-- Enter valid TAN value
-- Enter the correct value of Amount
-- Click on the Transfer button→ amount transfer successfully( confirmation message)

• For Cancel Component:


-- Enter the values of FAN, TAN, and amount.
-- Click on the Cancel button → all data should be cleared.
HOW TO ACHIEVE THE BEST RESULT VIA UNIT TESTING?

• Test cases must be independent because if there is any change or enhancement in requirement,
the test cases will not be affected.

• Naming conventions for unit test cases must be clear and consistent.

• During unit testing, the identified bugs must be fixed before jump on next phase of the SDLC.

• Only one code should be tested at one time.

• Adopt test cases with the writing of the code, if not doing so, the number of execution paths
will be increased.

• If there are changes in the code of any module, ensure the corresponding unit test is available
or not for that module.
ADVANTAGES AND DISADVANTAGES OF UNIT TESTING:

ADVANTAGES DISADVANTAGES

• Unit testing uses module approach due to • It cannot identify integration or broad level
that any part can be tested without waiting error as it works on units of the code.
for completion of another parts testing.
• In the unit testing, evaluation of all
• The developing team focuses on the execution paths is not possible, so unit
provided functionality of the unit and how testing is not able to catch each and every
functionality should look in unit test suits to error in a program.
understand the unit API.
• It is best suitable for conjunction with other
• Unit testing allows the developer to refactor testing activities.
code after a number of days and ensure the
module still working without any defect.
CONCLUSION:

Thus, Unit testing comes into picture when it


is required to test every function separately. It is
much reasonable to detect and fix bugs during this
testing and save time and cost, rather than finding at
the later stage of software development.
QUESTIONS

You might also like