Unit Testing: Done By: Harini.D 1732J08
Unit Testing: Done By: Harini.D 1732J08
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.
• 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.
• The aim behind unit testing is to validate unit components with its performance.
• 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 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.
• 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
Values Description
1234 accept
Copy and paste the value Error message→ type the value
Provide the values just like we did in From account number (FAN) components.
Provide the values just like we did in FAN and TAN components.
• 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.
• 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: