SlideShare une entreprise Scribd logo
1  sur  16
S U B M I T T E D B Y :
S U R A J K U M A R S I N G H
S O F T W A R E D E V E L O P E R
I B I R D S S O F T W A R E S E R V I C E S P V T . L T D .
1/24/2016Ibirds Software Services Pvt. Ltd.
1
Contents
1/24/2016Ibirds Software Services Pvt. Ltd.
2
 Introduction
 What to Test in Test Classes?
 Annotation in Test Classes
 Use Of Static Resource
 Importance of System.Assert
 Use Of Test.StartTest/StopTest Methods
 How To Write
 Utility Test Class
 Deployment
 Points to Remember
Introduction
1/24/2016Ibirds Software Services Pvt. Ltd.
3
 Ways of Testing : Only Through Interface.
 Why Test Class? -- TRUST
 Features Of test Classes
 While testing it does not made any changes to the real database.
 If your tests access organization data, this prevents accidental
deletions or modifications to existing records.
 No requirement for test data cleanup
 Test methods don't commit data. So We Do not find any track
record.
What To Test?
1/24/2016Ibirds Software Services Pvt. Ltd.
4
 Single action and Bulk Action(upto 200)
 “Null Pointer Exception test” (min 1).
 Positive Behavior (Expected Result).
 Negative Behavior(Acquire expected error).
 Restricted user
 Use runAs Method
 runAs(user):
 In Normal ways permissions and record sharing of the current user are
not taken into account.
 runAs(System.Version)
Annotation in Test Class
1/24/2016Ibirds Software Services Pvt. Ltd.
5
 @isTest :
 To Identify a Test Class.
 @IsTest(SeeAllData=true) :
 Open up data access to records in your organization.
 @isTest(SeeAllData=false) :
 For methods to who do not use Organization's Data.
 @TestVisible :
 Use to access private members and methods of testing class inside
Test Class.
 @TestVisible private static Integer recordNumber = 1; // in Class.
 Integer i = class.recordNumber; // in Test Classs.
Annotation in Test Class
1/24/2016Ibirds Software Services Pvt. Ltd.
6
 @testSetup :
 Prerequisite data for all test methods, or a common set of records that are available to
test methods
 Save Time – Need not to re-create record for each test Method.
 By Priority, this method have highest priority.
 Any changes(DML Operations) are not affected in between test methods.
 @testSetup static void methodName() {}
 Note:
 If @isTest(SeeAllData=true) is in use, Then it will be failed.
 If Multiple test setup methods are used in a test class, then in Order of execution
can’t be guaranteed.
 Any Exception will fails the whole test class.
 If a test setup method calls a non-test method of another class, no code coverage
is calculated for the non-test method.
Importance of System.Assert
1/24/2016Ibirds Software Services Pvt. Ltd.
7
 assert(condition, msg):
 Check the specified condition is true. If it is not, a error message is returned
that causes code execution to halt.
 assertEquals(expected, actual, msg) :
 Check the first two arguments are the same. If they are not, a error message
is returned that causes code execution to halt.
 assertNotEquals(expected, actual, msg) :
 Check the first two arguments are different. If they are the same, a
error message is returned that causes code execution to halt.
Start/Stop Test
1/24/2016Ibirds Software Services Pvt. Ltd.
8
 Test.StartTest():
 Marks the point in your test code when your test actually begins.
 Test.StopTest():
 The stopTest method marks the point in your test code when your test ends.
 Each test method is allowed to call this method only once.
 All of the code before this method should be used to
initialize variables, populate data structures, and so on,
allowing you to set up everything you need to run your test.
 Assigned a new set of governor limits.
 When stopTest is executed, all asynchronous processes are
run synchronously.
How to write Test Classes
1/24/2016Ibirds Software Services Pvt. Ltd.
9
 For Batch Class:
 Databese.execute() line must be in between Test.startTest() and Test.stopTest().
 For Standard Controller Class:
How to write Test Classes
1/24/2016Ibirds Software Services Pvt. Ltd.
10
 For Schedule Class:
 Method must be in between Test.startTest() and Test.stopTest().
Use Of Static Resource in Test Classes
1/24/2016Ibirds Software Services Pvt. Ltd.
11
 Test.loadData: Populate data in your test methods without having to
write many lines of code
 Use CSV File.
Common Test Utilities
1/24/2016Ibirds Software Services Pvt. Ltd.
12
 They Are Public test classes that contain reusable code for test data creation.
 Defined with the @isTest annotation to exclude from organization’s code size
limit.
 A class that contains all necessary information for creation of test object and
have values to full fill all validation rules.
Deployment
1/24/2016Ibirds Software Services Pvt. Ltd.
13
 At least 75% of your Apex code must be covered.
 When deploying Apex, each unit test in organization is executed by
default.
 System.debug, Test methods and test classes are not counted as part
of Apex code coverage.
 While only 75% of your Apex code must be covered by tests, your focus
shouldn't be on the percentage of code that is covered. Instead, you
should make sure that every use case of your application is covered,
including positive and negative cases, as well as bulk and single
records. This should lead to 75% or more of your code being covered by
unit tests.
Points To Remember
1/24/2016Ibirds Software Services Pvt. Ltd.
14
 All test methods should reside in a separate class.
 @isTest annotation at Beginning of class.
 Use Test.isRunningTest().
 A method without an assert statement is not considered a
test method.
 Use of Comments
 Do Not Use @isTest(SeeAllData = true) unless required(e.g
Products ).
 Use Test.runAs(user).
 Use Test Utility Class.
???????????
1/24/2016Ibirds Software Services Pvt. Ltd.
15
THE END
1/24/2016Ibirds Software Services Pvt. Ltd.
16

Contenu connexe

Tendances (20)

QAI QUEST 2016 Webinar Series: Pairwise Testing w/ Philip Lew
QAI QUEST 2016 Webinar Series: Pairwise Testing w/ Philip LewQAI QUEST 2016 Webinar Series: Pairwise Testing w/ Philip Lew
QAI QUEST 2016 Webinar Series: Pairwise Testing w/ Philip Lew
 
Unit and integration Testing
Unit and integration TestingUnit and integration Testing
Unit and integration Testing
 
Unit testing
Unit testingUnit testing
Unit testing
 
Junit4.0
Junit4.0Junit4.0
Junit4.0
 
Unit test
Unit testUnit test
Unit test
 
Workshop unit test
Workshop   unit testWorkshop   unit test
Workshop unit test
 
Unit Testing Concepts and Best Practices
Unit Testing Concepts and Best PracticesUnit Testing Concepts and Best Practices
Unit Testing Concepts and Best Practices
 
Unit testing
Unit testingUnit testing
Unit testing
 
Unit testing
Unit testingUnit testing
Unit testing
 
UNIT TESTING
UNIT TESTINGUNIT TESTING
UNIT TESTING
 
Tdd & unit test
Tdd & unit testTdd & unit test
Tdd & unit test
 
Pairwise testing - Strategic test case design
Pairwise testing - Strategic test case designPairwise testing - Strategic test case design
Pairwise testing - Strategic test case design
 
Unit tests & TDD
Unit tests & TDDUnit tests & TDD
Unit tests & TDD
 
Unit test
Unit testUnit test
Unit test
 
Unit Testing And Mocking
Unit Testing And MockingUnit Testing And Mocking
Unit Testing And Mocking
 
Testing and Mocking Object - The Art of Mocking.
Testing and Mocking Object - The Art of Mocking.Testing and Mocking Object - The Art of Mocking.
Testing and Mocking Object - The Art of Mocking.
 
Unit Test Presentation
Unit Test PresentationUnit Test Presentation
Unit Test Presentation
 
Unit Tests And Automated Testing
Unit Tests And Automated TestingUnit Tests And Automated Testing
Unit Tests And Automated Testing
 
Query Management system-Iv review
Query Management system-Iv reviewQuery Management system-Iv review
Query Management system-Iv review
 
Unit testing with JUnit
Unit testing with JUnitUnit testing with JUnit
Unit testing with JUnit
 

En vedette

Excursion Report of Jhanjhra Coal Mines
Excursion Report of Jhanjhra Coal MinesExcursion Report of Jhanjhra Coal Mines
Excursion Report of Jhanjhra Coal MinesAnurag Jha
 
160425 Speech by Jerry
160425 Speech by Jerry160425 Speech by Jerry
160425 Speech by JerryChun-Yi Lin
 
BHAGWANT UNIVERSITY
BHAGWANT UNIVERSITYBHAGWANT UNIVERSITY
BHAGWANT UNIVERSITYSuraj Singh
 
High School Exposition march 31, 2011
High School Exposition march 31, 2011High School Exposition march 31, 2011
High School Exposition march 31, 2011Jeffery Fullerton
 
Optimization of Blasting Parameters in open cast mines
Optimization of Blasting Parameters in open cast minesOptimization of Blasting Parameters in open cast mines
Optimization of Blasting Parameters in open cast minesAnurag Jha
 
Intranet Development in Drupal 7
Intranet Development in Drupal 7Intranet Development in Drupal 7
Intranet Development in Drupal 7Oxford City Council
 
Design For Change UA & See the Sea
Design For Change UA & See the SeaDesign For Change UA & See the Sea
Design For Change UA & See the SeaManifest_Mira
 
Transitional orientation 2008 official ducument
Transitional orientation 2008 official ducumentTransitional orientation 2008 official ducument
Transitional orientation 2008 official ducumentJeffery Fullerton
 
Quality Assurance Engineer_Muhammad Saad
Quality Assurance Engineer_Muhammad SaadQuality Assurance Engineer_Muhammad Saad
Quality Assurance Engineer_Muhammad SaadSaad Ali
 
Music and postoperative recovery
Music and postoperative recoveryMusic and postoperative recovery
Music and postoperative recoveryGerard A. Baltazar
 
Tarea 6 scopus
Tarea 6   scopusTarea 6   scopus
Tarea 6 scopusBea Panini
 
Production schedule 2
Production schedule 2Production schedule 2
Production schedule 2baldeep17_
 
Digital poetry text message
Digital poetry text messageDigital poetry text message
Digital poetry text messageIbnay Muneeb
 

En vedette (20)

Excursion Report of Jhanjhra Coal Mines
Excursion Report of Jhanjhra Coal MinesExcursion Report of Jhanjhra Coal Mines
Excursion Report of Jhanjhra Coal Mines
 
160425 Speech by Jerry
160425 Speech by Jerry160425 Speech by Jerry
160425 Speech by Jerry
 
BHAGWANT UNIVERSITY
BHAGWANT UNIVERSITYBHAGWANT UNIVERSITY
BHAGWANT UNIVERSITY
 
High School Exposition march 31, 2011
High School Exposition march 31, 2011High School Exposition march 31, 2011
High School Exposition march 31, 2011
 
Mathi
Mathi Mathi
Mathi
 
MECHANICS PRO PPT
MECHANICS PRO PPTMECHANICS PRO PPT
MECHANICS PRO PPT
 
Optimization of Blasting Parameters in open cast mines
Optimization of Blasting Parameters in open cast minesOptimization of Blasting Parameters in open cast mines
Optimization of Blasting Parameters in open cast mines
 
MECH_PROJECT
MECH_PROJECTMECH_PROJECT
MECH_PROJECT
 
Report
ReportReport
Report
 
Intranet Development in Drupal 7
Intranet Development in Drupal 7Intranet Development in Drupal 7
Intranet Development in Drupal 7
 
Design For Change UA & See the Sea
Design For Change UA & See the SeaDesign For Change UA & See the Sea
Design For Change UA & See the Sea
 
Transitional orientation 2008 official ducument
Transitional orientation 2008 official ducumentTransitional orientation 2008 official ducument
Transitional orientation 2008 official ducument
 
Certificate_1
Certificate_1Certificate_1
Certificate_1
 
Certificate_2
Certificate_2Certificate_2
Certificate_2
 
Quality Assurance Engineer_Muhammad Saad
Quality Assurance Engineer_Muhammad SaadQuality Assurance Engineer_Muhammad Saad
Quality Assurance Engineer_Muhammad Saad
 
Music and postoperative recovery
Music and postoperative recoveryMusic and postoperative recovery
Music and postoperative recovery
 
Tarea 6 scopus
Tarea 6   scopusTarea 6   scopus
Tarea 6 scopus
 
Water educators- talk
Water educators- talkWater educators- talk
Water educators- talk
 
Production schedule 2
Production schedule 2Production schedule 2
Production schedule 2
 
Digital poetry text message
Digital poetry text messageDigital poetry text message
Digital poetry text message
 

Similaire à Testclass [Autosaved]

Regression Optimizer
Regression OptimizerRegression Optimizer
Regression OptimizerShradha Singh
 
Software Testing
Software TestingSoftware Testing
Software TestingKiran Kumar
 
Object Oriented Testing
Object Oriented TestingObject Oriented Testing
Object Oriented TestingAMITJain879
 
An introduction to apex code test methods developer.force
An introduction to apex code test methods   developer.forceAn introduction to apex code test methods   developer.force
An introduction to apex code test methods developer.forcesendmail2cherukuri
 
Testers Desk Presentation
Testers Desk PresentationTesters Desk Presentation
Testers Desk PresentationQuality Testing
 
JUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkJUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkOnkar Deshpande
 
Chapter 3 SOFTWARE TESTING PROCESS
Chapter 3 SOFTWARE TESTING PROCESSChapter 3 SOFTWARE TESTING PROCESS
Chapter 3 SOFTWARE TESTING PROCESSst. michael
 
Chapter 8 - Software Testing.ppt
Chapter 8 - Software Testing.pptChapter 8 - Software Testing.ppt
Chapter 8 - Software Testing.pptGentaSahuri2
 
A Productive Method for Improving Test Effectiveness
A Productive Method for Improving Test EffectivenessA Productive Method for Improving Test Effectiveness
A Productive Method for Improving Test EffectivenessShradha Singh
 
Dev labs alliance top 20 testng interview questions for sdet
Dev labs alliance top 20 testng interview questions for sdetDev labs alliance top 20 testng interview questions for sdet
Dev labs alliance top 20 testng interview questions for sdetdevlabsalliance
 
Test design techniques
Test design techniquesTest design techniques
Test design techniquesOksana
 
UNIT TESTING PPT
UNIT TESTING PPTUNIT TESTING PPT
UNIT TESTING PPTsuhasreddy1
 
TestNG - The Next Generation of Unit Testing
TestNG - The Next Generation of Unit TestingTestNG - The Next Generation of Unit Testing
TestNG - The Next Generation of Unit TestingBethmi Gunasekara
 
Automation testing
Automation testingAutomation testing
Automation testingTomy Rhymond
 

Similaire à Testclass [Autosaved] (20)

Regression Optimizer
Regression OptimizerRegression Optimizer
Regression Optimizer
 
Software Testing
Software TestingSoftware Testing
Software Testing
 
Ch23
Ch23Ch23
Ch23
 
unit 1 (1).pptx
unit 1 (1).pptxunit 1 (1).pptx
unit 1 (1).pptx
 
Object Oriented Testing
Object Oriented TestingObject Oriented Testing
Object Oriented Testing
 
An introduction to apex code test methods developer.force
An introduction to apex code test methods   developer.forceAn introduction to apex code test methods   developer.force
An introduction to apex code test methods developer.force
 
Testers Desk Presentation
Testers Desk PresentationTesters Desk Presentation
Testers Desk Presentation
 
JUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkJUnit- A Unit Testing Framework
JUnit- A Unit Testing Framework
 
Chapter 3 SOFTWARE TESTING PROCESS
Chapter 3 SOFTWARE TESTING PROCESSChapter 3 SOFTWARE TESTING PROCESS
Chapter 3 SOFTWARE TESTING PROCESS
 
Chapter 8 - Software Testing.ppt
Chapter 8 - Software Testing.pptChapter 8 - Software Testing.ppt
Chapter 8 - Software Testing.ppt
 
TDD Best Practices
TDD Best PracticesTDD Best Practices
TDD Best Practices
 
A Productive Method for Improving Test Effectiveness
A Productive Method for Improving Test EffectivenessA Productive Method for Improving Test Effectiveness
A Productive Method for Improving Test Effectiveness
 
Test automation
Test automationTest automation
Test automation
 
Testing
TestingTesting
Testing
 
Dev labs alliance top 20 testng interview questions for sdet
Dev labs alliance top 20 testng interview questions for sdetDev labs alliance top 20 testng interview questions for sdet
Dev labs alliance top 20 testng interview questions for sdet
 
Test design techniques
Test design techniquesTest design techniques
Test design techniques
 
UNIT TESTING PPT
UNIT TESTING PPTUNIT TESTING PPT
UNIT TESTING PPT
 
Unit2 for st
Unit2 for stUnit2 for st
Unit2 for st
 
TestNG - The Next Generation of Unit Testing
TestNG - The Next Generation of Unit TestingTestNG - The Next Generation of Unit Testing
TestNG - The Next Generation of Unit Testing
 
Automation testing
Automation testingAutomation testing
Automation testing
 

Testclass [Autosaved]

  • 1. S U B M I T T E D B Y : S U R A J K U M A R S I N G H S O F T W A R E D E V E L O P E R I B I R D S S O F T W A R E S E R V I C E S P V T . L T D . 1/24/2016Ibirds Software Services Pvt. Ltd. 1
  • 2. Contents 1/24/2016Ibirds Software Services Pvt. Ltd. 2  Introduction  What to Test in Test Classes?  Annotation in Test Classes  Use Of Static Resource  Importance of System.Assert  Use Of Test.StartTest/StopTest Methods  How To Write  Utility Test Class  Deployment  Points to Remember
  • 3. Introduction 1/24/2016Ibirds Software Services Pvt. Ltd. 3  Ways of Testing : Only Through Interface.  Why Test Class? -- TRUST  Features Of test Classes  While testing it does not made any changes to the real database.  If your tests access organization data, this prevents accidental deletions or modifications to existing records.  No requirement for test data cleanup  Test methods don't commit data. So We Do not find any track record.
  • 4. What To Test? 1/24/2016Ibirds Software Services Pvt. Ltd. 4  Single action and Bulk Action(upto 200)  “Null Pointer Exception test” (min 1).  Positive Behavior (Expected Result).  Negative Behavior(Acquire expected error).  Restricted user  Use runAs Method  runAs(user):  In Normal ways permissions and record sharing of the current user are not taken into account.  runAs(System.Version)
  • 5. Annotation in Test Class 1/24/2016Ibirds Software Services Pvt. Ltd. 5  @isTest :  To Identify a Test Class.  @IsTest(SeeAllData=true) :  Open up data access to records in your organization.  @isTest(SeeAllData=false) :  For methods to who do not use Organization's Data.  @TestVisible :  Use to access private members and methods of testing class inside Test Class.  @TestVisible private static Integer recordNumber = 1; // in Class.  Integer i = class.recordNumber; // in Test Classs.
  • 6. Annotation in Test Class 1/24/2016Ibirds Software Services Pvt. Ltd. 6  @testSetup :  Prerequisite data for all test methods, or a common set of records that are available to test methods  Save Time – Need not to re-create record for each test Method.  By Priority, this method have highest priority.  Any changes(DML Operations) are not affected in between test methods.  @testSetup static void methodName() {}  Note:  If @isTest(SeeAllData=true) is in use, Then it will be failed.  If Multiple test setup methods are used in a test class, then in Order of execution can’t be guaranteed.  Any Exception will fails the whole test class.  If a test setup method calls a non-test method of another class, no code coverage is calculated for the non-test method.
  • 7. Importance of System.Assert 1/24/2016Ibirds Software Services Pvt. Ltd. 7  assert(condition, msg):  Check the specified condition is true. If it is not, a error message is returned that causes code execution to halt.  assertEquals(expected, actual, msg) :  Check the first two arguments are the same. If they are not, a error message is returned that causes code execution to halt.  assertNotEquals(expected, actual, msg) :  Check the first two arguments are different. If they are the same, a error message is returned that causes code execution to halt.
  • 8. Start/Stop Test 1/24/2016Ibirds Software Services Pvt. Ltd. 8  Test.StartTest():  Marks the point in your test code when your test actually begins.  Test.StopTest():  The stopTest method marks the point in your test code when your test ends.  Each test method is allowed to call this method only once.  All of the code before this method should be used to initialize variables, populate data structures, and so on, allowing you to set up everything you need to run your test.  Assigned a new set of governor limits.  When stopTest is executed, all asynchronous processes are run synchronously.
  • 9. How to write Test Classes 1/24/2016Ibirds Software Services Pvt. Ltd. 9  For Batch Class:  Databese.execute() line must be in between Test.startTest() and Test.stopTest().  For Standard Controller Class:
  • 10. How to write Test Classes 1/24/2016Ibirds Software Services Pvt. Ltd. 10  For Schedule Class:  Method must be in between Test.startTest() and Test.stopTest().
  • 11. Use Of Static Resource in Test Classes 1/24/2016Ibirds Software Services Pvt. Ltd. 11  Test.loadData: Populate data in your test methods without having to write many lines of code  Use CSV File.
  • 12. Common Test Utilities 1/24/2016Ibirds Software Services Pvt. Ltd. 12  They Are Public test classes that contain reusable code for test data creation.  Defined with the @isTest annotation to exclude from organization’s code size limit.  A class that contains all necessary information for creation of test object and have values to full fill all validation rules.
  • 13. Deployment 1/24/2016Ibirds Software Services Pvt. Ltd. 13  At least 75% of your Apex code must be covered.  When deploying Apex, each unit test in organization is executed by default.  System.debug, Test methods and test classes are not counted as part of Apex code coverage.  While only 75% of your Apex code must be covered by tests, your focus shouldn't be on the percentage of code that is covered. Instead, you should make sure that every use case of your application is covered, including positive and negative cases, as well as bulk and single records. This should lead to 75% or more of your code being covered by unit tests.
  • 14. Points To Remember 1/24/2016Ibirds Software Services Pvt. Ltd. 14  All test methods should reside in a separate class.  @isTest annotation at Beginning of class.  Use Test.isRunningTest().  A method without an assert statement is not considered a test method.  Use of Comments  Do Not Use @isTest(SeeAllData = true) unless required(e.g Products ).  Use Test.runAs(user).  Use Test Utility Class.
  • 16. THE END 1/24/2016Ibirds Software Services Pvt. Ltd. 16

Notes de l'éditeur

  1. Hi
  2. sdkjfdkjf