SlideShare a Scribd company logo
By Ajinkya Prabhune
 What is Unit Testing ?
 Example.
 When to use Unit Testing ?
 How to write Unit Test ?
 FrameWorks Examples.
 The primary goal of unit testing is to take the
smallest piece of testable software in the application,
isolate it from the remainder of the code, and
determine whether it behaves exactly as you expect.
 Good Definition for Unit Test- (define later)
Unit Test is an automated piece of code that invokes
the method or class being tested and then check
some assumption about the logical behavior of that
Method/Class. Unit Test is almost always written
using a Unit Testing Framework. It can be written
easily & runs quickly.
It is fully automated, trustworthy, readable and
maintainable.
 Assume we have a
Addition class that
we’d like to test.
 We can now create a
simple test class which
will call this method.
 MathOperation
operation = new
MathOperation();
operation.Addition(3,4)
value = 7 should be
expected for a
successful Test.
public class MathOperation
{
public int Addition(int a, int b)
{
if(a==null || b==null)
{
System.Out.Println(“Null value
occured”)
return -1;
}
else
{
return a+b;
}
}
}
1 . It helps you write better Code.
 In addition to finding errors in your code, unit testing can help
you during the initial development of your class or module's
public interface.
 Unit tests force you to think about how another developer will
want to use your code while you're writing that code.
2. Writing test cases will save you time later.
3. Unit tests provide immediate feedback on your code.
 You don't have to wait until after code in a separate part of the
application is written before you can test and know whether your
code works.
4. Unit Tests should be written at each stage of development of
your code.
so that continuous check of your code is maintained and saves
you efforts during the final release of the software.
 The Tests should be Through.
1. You should only be satisfied with your unit
tests when
you’re confident that your unit tests thoroughly
verify that
your code works as we expect it to work.
2. Unit tests should exercise the expected as well
as the
unexpected conditions in your code.
3. Special attention should be paid to areas of
code that are
particularly likely to break.
 The Test should be Repeatable.
1. Every one of your unit tests should be able to be
run repeatedly and continue to produce the same
results, regardless of the environment in which the
tests are being run.
2. Your unit tests should not rely on hard-coded
server urls.
3. Unit tests must be written in either a sandbox org
or in a developer org.
 The Test should be Independent
1. Your unit tests should only test one aspect of
your code at a time, so that it is easy to understand
the purpose of each unit test. Properly written, and
well-decomposed unit tests are an excellent source
of documentation.
2. Each Test should be independent of the other
Test.
 Junit – JAVA
 Nunit- .Net
RIA 05 - Unit Testing by Ajinkya Prabhune

More Related Content

PDF
Unit testing in Force.com platform
PPTX
Unit testing and test driven development using vs
PPTX
Unit Tests And Automated Testing
PPTX
Moq presentation
PPTX
Test driven development in .Net - 2010 + Eclipse
PPTX
Unit testing using Munit Part 1
PPTX
Unit testing with NUnit
PDF
Apex trigger framework Salesforce #ApexTrigger #Salesforce #SFDCPanther
Unit testing in Force.com platform
Unit testing and test driven development using vs
Unit Tests And Automated Testing
Moq presentation
Test driven development in .Net - 2010 + Eclipse
Unit testing using Munit Part 1
Unit testing with NUnit
Apex trigger framework Salesforce #ApexTrigger #Salesforce #SFDCPanther

What's hot (20)

PPTX
How to be an awesome test automation professional
PPTX
Unit testing, UI testing and Test Driven Development in Visual Studio 2012
PDF
All About Test Class in #Salesforce
PPT
Nguyenvandungb seminar
PPT
N Unit Presentation
PDF
Test setup methods in Salesforce Apex Class
PDF
Unit Testing Fundamentals
ODP
Beginners - Get Started With Unit Testing in .NET
PDF
An Introduction to Unit Test Using NUnit
PPTX
Fundamentals of unit testing
PPTX
Unit & integration testing
PPTX
Unit Testing
PDF
How and what to unit test
PPTX
NUnit Features Presentation
PPTX
Intro To Unit and integration Testing
PPTX
Presentation
PPTX
How to improve code quality for iOS apps?
PDF
Keyword Driven Testing
How to be an awesome test automation professional
Unit testing, UI testing and Test Driven Development in Visual Studio 2012
All About Test Class in #Salesforce
Nguyenvandungb seminar
N Unit Presentation
Test setup methods in Salesforce Apex Class
Unit Testing Fundamentals
Beginners - Get Started With Unit Testing in .NET
An Introduction to Unit Test Using NUnit
Fundamentals of unit testing
Unit & integration testing
Unit Testing
How and what to unit test
NUnit Features Presentation
Intro To Unit and integration Testing
Presentation
How to improve code quality for iOS apps?
Keyword Driven Testing
Ad

Viewers also liked (6)

PPTX
Practical unit testing in c & c++
PDF
Unit-Testing Bad-Practices by Example
PDF
Unit testing best practices
PPTX
Istqb foundation level day 1
PPTX
Unit Testing Concepts and Best Practices
PPTX
UNIT TESTING PPT
Practical unit testing in c & c++
Unit-Testing Bad-Practices by Example
Unit testing best practices
Istqb foundation level day 1
Unit Testing Concepts and Best Practices
UNIT TESTING PPT
Ad

Similar to RIA 05 - Unit Testing by Ajinkya Prabhune (20)

PDF
How Unit Testing Strengthens Software Reliability
PDF
What Is Unit Testing_ A Complete Guide With Examples.pdf
PDF
What Is Unit Testing A Complete Guide With Examples.pdf
PPTX
Unit testing & TDD concepts with best practice guidelines.
PDF
Unit Testing in Angular
PPS
Unit Testing
PPS
Why Unit Testingl
PPS
Why Unit Testingl
PPS
Why unit testingl
PDF
Unit testing, principles
PDF
JAVASCRIPT Test Driven Development & Jasmine
PDF
What is Unit Testing_ - A Complete Guide.pdf
PDF
What is Unit Testing? - A Complete Guide
PDF
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
PDF
TDD Workshop UTN 2012
PPTX
Test driven development(tdd)
PPTX
Project Onion unit test environment
PPTX
unittesting-190620114546 (1).pptx document
PDF
utplsql.pdf
PPTX
SOFTWARE TESTING UNIT-4
How Unit Testing Strengthens Software Reliability
What Is Unit Testing_ A Complete Guide With Examples.pdf
What Is Unit Testing A Complete Guide With Examples.pdf
Unit testing & TDD concepts with best practice guidelines.
Unit Testing in Angular
Unit Testing
Why Unit Testingl
Why Unit Testingl
Why unit testingl
Unit testing, principles
JAVASCRIPT Test Driven Development & Jasmine
What is Unit Testing_ - A Complete Guide.pdf
What is Unit Testing? - A Complete Guide
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
TDD Workshop UTN 2012
Test driven development(tdd)
Project Onion unit test environment
unittesting-190620114546 (1).pptx document
utplsql.pdf
SOFTWARE TESTING UNIT-4

More from Johannes Hoppe (20)

PDF
2017 - NoSQL Vorlesung Mosbach
PPTX
NoSQL - Hands on
PDF
Einführung in Angular 2
PDF
MDC kompakt 2014: Hybride Apps mit Cordova, AngularJS und Ionic
PPTX
2015 02-09 - NoSQL Vorlesung Mosbach
PDF
2012-06-25 - MapReduce auf Azure
PDF
2013-06-25 - HTML5 & JavaScript Security
PDF
2013-06-24 - Software Craftsmanship with JavaScript
PDF
2013-06-15 - Software Craftsmanship mit JavaScript
PDF
2013 05-03 - HTML5 & JavaScript Security
PDF
2013-03-23 - NoSQL Spartakiade
PDF
2013 02-26 - Software Tests with Mongo db
PDF
2013-02-21 - .NET UG Rhein-Neckar: JavaScript Best Practices
PDF
2012-10-16 - WebTechCon 2012: HTML5 & WebGL
PDF
2012-10-12 - NoSQL in .NET - mit Redis und Mongodb
PDF
2012-09-18 - HTML5 & WebGL
PDF
2012-09-17 - WDC12: Node.js & MongoDB
PDF
2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)
PDF
2012-05-14 NoSQL in .NET - mit Redis und MongoDB
PDF
2012-05-10 - UG Karlsruhe: NoSQL in .NET - mit Redis und MongoDB
2017 - NoSQL Vorlesung Mosbach
NoSQL - Hands on
Einführung in Angular 2
MDC kompakt 2014: Hybride Apps mit Cordova, AngularJS und Ionic
2015 02-09 - NoSQL Vorlesung Mosbach
2012-06-25 - MapReduce auf Azure
2013-06-25 - HTML5 & JavaScript Security
2013-06-24 - Software Craftsmanship with JavaScript
2013-06-15 - Software Craftsmanship mit JavaScript
2013 05-03 - HTML5 & JavaScript Security
2013-03-23 - NoSQL Spartakiade
2013 02-26 - Software Tests with Mongo db
2013-02-21 - .NET UG Rhein-Neckar: JavaScript Best Practices
2012-10-16 - WebTechCon 2012: HTML5 & WebGL
2012-10-12 - NoSQL in .NET - mit Redis und Mongodb
2012-09-18 - HTML5 & WebGL
2012-09-17 - WDC12: Node.js & MongoDB
2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)
2012-05-14 NoSQL in .NET - mit Redis und MongoDB
2012-05-10 - UG Karlsruhe: NoSQL in .NET - mit Redis und MongoDB

Recently uploaded (20)

PDF
Modernizing your data center with Dell and AMD
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
Cloud computing and distributed systems.
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Empathic Computing: Creating Shared Understanding
PDF
Advanced Soft Computing BINUS July 2025.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
cuic standard and advanced reporting.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Modernizing your data center with Dell and AMD
Mobile App Security Testing_ A Comprehensive Guide.pdf
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Cloud computing and distributed systems.
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
The AUB Centre for AI in Media Proposal.docx
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Network Security Unit 5.pdf for BCA BBA.
Diabetes mellitus diagnosis method based random forest with bat algorithm
Empathic Computing: Creating Shared Understanding
Advanced Soft Computing BINUS July 2025.pdf
Chapter 3 Spatial Domain Image Processing.pdf
cuic standard and advanced reporting.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx

RIA 05 - Unit Testing by Ajinkya Prabhune

  • 2.  What is Unit Testing ?  Example.  When to use Unit Testing ?  How to write Unit Test ?  FrameWorks Examples.
  • 3.  The primary goal of unit testing is to take the smallest piece of testable software in the application, isolate it from the remainder of the code, and determine whether it behaves exactly as you expect.  Good Definition for Unit Test- (define later) Unit Test is an automated piece of code that invokes the method or class being tested and then check some assumption about the logical behavior of that Method/Class. Unit Test is almost always written using a Unit Testing Framework. It can be written easily & runs quickly. It is fully automated, trustworthy, readable and maintainable.
  • 4.  Assume we have a Addition class that we’d like to test.  We can now create a simple test class which will call this method.  MathOperation operation = new MathOperation(); operation.Addition(3,4) value = 7 should be expected for a successful Test. public class MathOperation { public int Addition(int a, int b) { if(a==null || b==null) { System.Out.Println(“Null value occured”) return -1; } else { return a+b; } } }
  • 5. 1 . It helps you write better Code.  In addition to finding errors in your code, unit testing can help you during the initial development of your class or module's public interface.  Unit tests force you to think about how another developer will want to use your code while you're writing that code. 2. Writing test cases will save you time later. 3. Unit tests provide immediate feedback on your code.  You don't have to wait until after code in a separate part of the application is written before you can test and know whether your code works. 4. Unit Tests should be written at each stage of development of your code. so that continuous check of your code is maintained and saves you efforts during the final release of the software.
  • 6.  The Tests should be Through. 1. You should only be satisfied with your unit tests when you’re confident that your unit tests thoroughly verify that your code works as we expect it to work. 2. Unit tests should exercise the expected as well as the unexpected conditions in your code. 3. Special attention should be paid to areas of code that are particularly likely to break.
  • 7.  The Test should be Repeatable. 1. Every one of your unit tests should be able to be run repeatedly and continue to produce the same results, regardless of the environment in which the tests are being run. 2. Your unit tests should not rely on hard-coded server urls. 3. Unit tests must be written in either a sandbox org or in a developer org.
  • 8.  The Test should be Independent 1. Your unit tests should only test one aspect of your code at a time, so that it is easy to understand the purpose of each unit test. Properly written, and well-decomposed unit tests are an excellent source of documentation. 2. Each Test should be independent of the other Test.
  • 9.  Junit – JAVA  Nunit- .Net