SlideShare a Scribd company logo
1 of 32
CSE376
UNIT - 1
What Is Automation Testing?
 Automation Testing is a technique using an
automation tool to write and execute tester's test
scripts and cases..
 The testing tool takes actual outcomes and compares it
with the expected result to generate detailed test
reports.
 Since test automation demands a considerable
investment of resources and money,
 We should define:
1. when to do automation,
2. the scope of the automation
3. best tool of automation.
 Good planning practices can save us from high costs.
In the automation process, steps involved
are
1. Selecting the Test tool
2. Define scope of automation
3. Planning, design, and development
4. Test execution
5. Maintenance
 Testing is an essential part of product development,
especially to guarantee quality.
 Many smaller and mid-sized companies don’t give testing
much attention even though it’s essential for delivering a
strong product.
 Some companies prefer to do manual testing, although
that’s not the only best approach.
 The next logical step is automating your testing process.
 Manual testing should be minimized at all costs.
 Test automation increases overall software development
efficiency and allows for more robust tools to be built.
Benefits
 Faster Feedback Cycle
 Saves Time
 Reduced Business Expenses
 Higher Test Coverage
 Reusability of Test Suite
 Faster Time to Market
 Improved Accuracy
 Less Stress on QA Team
 Quick Determination the Stability of Your Build
 Eliminate Human Error
Benefits
 Ability To Perform Testing On Multiple Platforms In Parallel
 Accelerate Cross Browser Testing
 Distributed Test Execution
 Data Driven Testing
Most popular tools for automation
testing
 The most popular test tool for automation testing are
• QTP (HP UFT)
• Rational Robot
• Selenium
Why JUnit?
 JUnit is one of the most popular unit testing frameworks for Java development.
 Unit testing is an important part in Test Driven Development (TDD) as it helps
finding problems in the code as early as possible, especially when you make
changes to the existing code you can run unit tests again to make sure that the
changes do not break the application (regression).
 JUnit is supported by almost any Java IDEs and build tools, thus it is the default
choice of programmers to test their code.
 Eclipse has very good support for JUnit - the IDE is shipped with JUnit as its
default testing library.
 Thus writing and running unit tests with JUnit in Eclipse is quick, easy and
productive.
Structure of a Test Class
This Calculator class has two methods add() and subtract().
Now we want to write a test class to ensure that these
methods are working correctly. With JUnit, the test class
can have the following structure:
Annotations used in this test class
 @BeforeClass:
 Code in this method is executed only once, before all test methods in the test
class. Typically you put code that prepares test environment here, e.g.
initializing resources such as opening a database connection. The method
marked with this annotation must be static.

 @Before:
 Code in this method is executed before every test method in the test class. So
typically you put repeated code that must be executed before each test method
here.

 @Test:
 This annotation specifies the annotated method is a test method. You can notice the
naming convention for test method is the method name starts with test, followed by
the name of the method in the class being tested. This Calculator class has two
methods add() and subtract(), hence the test methods
are testAdd() and testSubtract().
 @After:
 Code in this method is executed after every test method in the test class. So typically
you put repeated code that must be executed after each test method here.
NOTE:
The above-mentioned annotations are in JUnit 4.
 @AfterClass:
 Code in this method is executed only once, after all test methods in the test
class. Due to this behavior, you can put code to clean up test environment here,
e.g. closing the database connection. Note that this kind of method must be
static.
 Except the test methods, the other kinds of method are optional. So you
implement them in the test class only if it is necessary.
JUnit 5 changes in annotations
 From JUnit 5,
 @BeforeClass changes to @BeforeAll;
 @Before changes to @BeforeEach;
 @After changes to @AfterEach;
 @AfterClass changes to @AfterAll.
 This change in JUnit 5 reflects better meaning of the annotations.
With JUnit 5, the structure of a test class looks like this:
To be noted:
 In JUnit 4, you need to import the annotations from
the org.junit package, but in JUnit 5 you need to import them from
the org.junit.jupiter.api package.
Using Assert Statement in Test Methods
 In a test method, we use an assert statement to verify whether the code under
test produces the result as expected or not.
 If the result is as expected, the tested code passes the test case. Otherwise
the tested code fails the test case.
 We use the assertEquals() method from the class org.junit.Assert via
static import:
 you can use the fail() method to fail the test immediately, for example:
Use the fail() method to indicate that a method is not
yet implemented so when the test class is executed, it will
fail.
 The assertEquals() method compares two values: the expected result
and the actual value returned from the tested code.
 If the two values are equal, the method returns normally indicating the tested
code passes the test case.
 If the two values are not equal, the method
throws java.lang.AssertionError indicating the tested code fails the
test case.
 And programmers must fix the code until it passes the test case.
JUnit provides many assert()methods, and
here are some commonly used ones:
• assertEquals(expected, actual): asserts that two values are equal. The values
can be of any primitive types or Objects.
• assertNotEquals(expected, actual): asserts that two arguments are not equal.
The values can be of any primitive types or Object.
• assertTrue(boolean condition): asserts that a condition is true.
• assertFalse(boolean condition): asserts that a condition is false.
• assertNull(Object): asserts that an object is null.
• assertNotNull(Object): asserts that an object is not null.
• assertSame(Object expected, Object actual): asserts that two objects
refer to the same object.
• assertNotSame(Object unexpected, Object actual): asserts that two
objects do not refer to the same object.
You can see the green indicator bar in the upper-right
corner indicating that the test case has been executed
successfully - the code under test passes the test case.
If the test fails, the status indicator becomes red and the
failure trace is printed:
This is the result of running the testSubtract() method,
The class Calculator passes two test methods in the CalculatorTest class.

More Related Content

Similar to unit 1 (1).pptx

Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++Hong Le Van
 
Java Unit Test - JUnit
Java Unit Test - JUnitJava Unit Test - JUnit
Java Unit Test - JUnitAktuğ Urun
 
Test driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + EclipseTest driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + EclipseUTC Fire & Security
 
Unit testing
Unit testingUnit testing
Unit testingmedsherb
 
Unit Testing in .NET Core 7.0 with XUnit.pptx
Unit Testing in .NET Core 7.0 with XUnit.pptxUnit Testing in .NET Core 7.0 with XUnit.pptx
Unit Testing in .NET Core 7.0 with XUnit.pptxKnoldus Inc.
 
Unit Testng with PHP Unit - A Step by Step Training
Unit Testng with PHP Unit - A Step by Step TrainingUnit Testng with PHP Unit - A Step by Step Training
Unit Testng with PHP Unit - A Step by Step TrainingRam Awadh Prasad, PMP
 
Unit testing & TDD concepts with best practice guidelines.
Unit testing & TDD concepts with best practice guidelines.Unit testing & TDD concepts with best practice guidelines.
Unit testing & TDD concepts with best practice guidelines.Mohamed Taman
 
AUTOCODECOVERGEN: PROTOTYPE OF DATA DRIVEN UNIT TEST GENRATION TOOL THAT GUAR...
AUTOCODECOVERGEN: PROTOTYPE OF DATA DRIVEN UNIT TEST GENRATION TOOL THAT GUAR...AUTOCODECOVERGEN: PROTOTYPE OF DATA DRIVEN UNIT TEST GENRATION TOOL THAT GUAR...
AUTOCODECOVERGEN: PROTOTYPE OF DATA DRIVEN UNIT TEST GENRATION TOOL THAT GUAR...acijjournal
 
Effective Unit Test Style Guide
Effective Unit Test Style GuideEffective Unit Test Style Guide
Effective Unit Test Style GuideJacky Lai
 

Similar to unit 1 (1).pptx (20)

Unit testing with JUnit
Unit testing with JUnitUnit testing with JUnit
Unit testing with JUnit
 
Introduction to JUnit
Introduction to JUnitIntroduction to JUnit
Introduction to JUnit
 
TDD Workshop UTN 2012
TDD Workshop UTN 2012TDD Workshop UTN 2012
TDD Workshop UTN 2012
 
Workshop unit test
Workshop   unit testWorkshop   unit test
Workshop unit test
 
Testing
TestingTesting
Testing
 
Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++
 
Junit
JunitJunit
Junit
 
Java Unit Test - JUnit
Java Unit Test - JUnitJava Unit Test - JUnit
Java Unit Test - JUnit
 
software testing
software testingsoftware testing
software testing
 
Test driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + EclipseTest driven development in .Net - 2010 + Eclipse
Test driven development in .Net - 2010 + Eclipse
 
8-testing.pptx
8-testing.pptx8-testing.pptx
8-testing.pptx
 
Unit testing
Unit testingUnit testing
Unit testing
 
Unit Testing in .NET Core 7.0 with XUnit.pptx
Unit Testing in .NET Core 7.0 with XUnit.pptxUnit Testing in .NET Core 7.0 with XUnit.pptx
Unit Testing in .NET Core 7.0 with XUnit.pptx
 
Unit Testng with PHP Unit - A Step by Step Training
Unit Testng with PHP Unit - A Step by Step TrainingUnit Testng with PHP Unit - A Step by Step Training
Unit Testng with PHP Unit - A Step by Step Training
 
Unit testing & TDD concepts with best practice guidelines.
Unit testing & TDD concepts with best practice guidelines.Unit testing & TDD concepts with best practice guidelines.
Unit testing & TDD concepts with best practice guidelines.
 
AUTOCODECOVERGEN: PROTOTYPE OF DATA DRIVEN UNIT TEST GENRATION TOOL THAT GUAR...
AUTOCODECOVERGEN: PROTOTYPE OF DATA DRIVEN UNIT TEST GENRATION TOOL THAT GUAR...AUTOCODECOVERGEN: PROTOTYPE OF DATA DRIVEN UNIT TEST GENRATION TOOL THAT GUAR...
AUTOCODECOVERGEN: PROTOTYPE OF DATA DRIVEN UNIT TEST GENRATION TOOL THAT GUAR...
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Effective Unit Test Style Guide
Effective Unit Test Style GuideEffective Unit Test Style Guide
Effective Unit Test Style Guide
 
Test automation
Test automationTest automation
Test automation
 
TDD Best Practices
TDD Best PracticesTDD Best Practices
TDD Best Practices
 

Recently uploaded

DAKSHIN BIHAR GRAMIN BANK: REDEFINING THE DIGITAL BANKING EXPERIENCE WITH A U...
DAKSHIN BIHAR GRAMIN BANK: REDEFINING THE DIGITAL BANKING EXPERIENCE WITH A U...DAKSHIN BIHAR GRAMIN BANK: REDEFINING THE DIGITAL BANKING EXPERIENCE WITH A U...
DAKSHIN BIHAR GRAMIN BANK: REDEFINING THE DIGITAL BANKING EXPERIENCE WITH A U...Rishabh Aryan
 
原版1:1定制堪培拉大学毕业证(UC毕业证)#文凭成绩单#真实留信学历认证永久存档
原版1:1定制堪培拉大学毕业证(UC毕业证)#文凭成绩单#真实留信学历认证永久存档原版1:1定制堪培拉大学毕业证(UC毕业证)#文凭成绩单#真实留信学历认证永久存档
原版1:1定制堪培拉大学毕业证(UC毕业证)#文凭成绩单#真实留信学历认证永久存档208367051
 
Unveiling the Future: Columbus, Ohio Condominiums Through the Lens of 3D Arch...
Unveiling the Future: Columbus, Ohio Condominiums Through the Lens of 3D Arch...Unveiling the Future: Columbus, Ohio Condominiums Through the Lens of 3D Arch...
Unveiling the Future: Columbus, Ohio Condominiums Through the Lens of 3D Arch...Yantram Animation Studio Corporation
 
MT. Marseille an Archipelago. Strategies for Integrating Residential Communit...
MT. Marseille an Archipelago. Strategies for Integrating Residential Communit...MT. Marseille an Archipelago. Strategies for Integrating Residential Communit...
MT. Marseille an Archipelago. Strategies for Integrating Residential Communit...katerynaivanenko1
 
How to Empower the future of UX Design with Gen AI
How to Empower the future of UX Design with Gen AIHow to Empower the future of UX Design with Gen AI
How to Empower the future of UX Design with Gen AIyuj
 
Iconic Global Solution - web design, Digital Marketing services
Iconic Global Solution - web design, Digital Marketing servicesIconic Global Solution - web design, Digital Marketing services
Iconic Global Solution - web design, Digital Marketing servicesIconic global solution
 
Design and Managing Service in the field of tourism and hospitality industry
Design and Managing Service in the field of tourism and hospitality industryDesign and Managing Service in the field of tourism and hospitality industry
Design and Managing Service in the field of tourism and hospitality industryrioverosanniejoy
 
Dubai Calls Girl Tapes O525547819 Real Tapes Escort Services Dubai
Dubai Calls Girl Tapes O525547819 Real Tapes Escort Services DubaiDubai Calls Girl Tapes O525547819 Real Tapes Escort Services Dubai
Dubai Calls Girl Tapes O525547819 Real Tapes Escort Services Dubaikojalkojal131
 
cda.pptx critical discourse analysis ppt
cda.pptx critical discourse analysis pptcda.pptx critical discourse analysis ppt
cda.pptx critical discourse analysis pptMaryamAfzal41
 
Call Girls Meghani Nagar 7397865700 Independent Call Girls
Call Girls Meghani Nagar 7397865700  Independent Call GirlsCall Girls Meghani Nagar 7397865700  Independent Call Girls
Call Girls Meghani Nagar 7397865700 Independent Call Girlsssuser7cb4ff
 
PORTFOLIO DE ARQUITECTURA CRISTOBAL HERAUD 2024
PORTFOLIO DE ARQUITECTURA CRISTOBAL HERAUD 2024PORTFOLIO DE ARQUITECTURA CRISTOBAL HERAUD 2024
PORTFOLIO DE ARQUITECTURA CRISTOBAL HERAUD 2024CristobalHeraud
 
FiveHypotheses_UIDMasterclass_18April2024.pdf
FiveHypotheses_UIDMasterclass_18April2024.pdfFiveHypotheses_UIDMasterclass_18April2024.pdf
FiveHypotheses_UIDMasterclass_18April2024.pdfShivakumar Viswanathan
 
ARt app | UX Case Study
ARt app | UX Case StudyARt app | UX Case Study
ARt app | UX Case StudySophia Viganò
 
在线办理ohio毕业证俄亥俄大学毕业证成绩单留信学历认证
在线办理ohio毕业证俄亥俄大学毕业证成绩单留信学历认证在线办理ohio毕业证俄亥俄大学毕业证成绩单留信学历认证
在线办理ohio毕业证俄亥俄大学毕业证成绩单留信学历认证nhjeo1gg
 
办理卡尔顿大学毕业证成绩单|购买加拿大文凭证书
办理卡尔顿大学毕业证成绩单|购买加拿大文凭证书办理卡尔顿大学毕业证成绩单|购买加拿大文凭证书
办理卡尔顿大学毕业证成绩单|购买加拿大文凭证书zdzoqco
 
2024新版美国旧金山州立大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
2024新版美国旧金山州立大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree2024新版美国旧金山州立大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
2024新版美国旧金山州立大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degreeyuu sss
 
Passbook project document_april_21__.pdf
Passbook project document_april_21__.pdfPassbook project document_april_21__.pdf
Passbook project document_april_21__.pdfvaibhavkanaujia
 
原版美国亚利桑那州立大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
原版美国亚利桑那州立大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree原版美国亚利桑那州立大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
原版美国亚利桑那州立大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degreeyuu sss
 
8377877756 Full Enjoy @24/7 Call Girls in Nirman Vihar Delhi NCR
8377877756 Full Enjoy @24/7 Call Girls in Nirman Vihar Delhi NCR8377877756 Full Enjoy @24/7 Call Girls in Nirman Vihar Delhi NCR
8377877756 Full Enjoy @24/7 Call Girls in Nirman Vihar Delhi NCRdollysharma2066
 
Call Girls in Ashok Nagar Delhi ✡️9711147426✡️ Escorts Service
Call Girls in Ashok Nagar Delhi ✡️9711147426✡️ Escorts ServiceCall Girls in Ashok Nagar Delhi ✡️9711147426✡️ Escorts Service
Call Girls in Ashok Nagar Delhi ✡️9711147426✡️ Escorts Servicejennyeacort
 

Recently uploaded (20)

DAKSHIN BIHAR GRAMIN BANK: REDEFINING THE DIGITAL BANKING EXPERIENCE WITH A U...
DAKSHIN BIHAR GRAMIN BANK: REDEFINING THE DIGITAL BANKING EXPERIENCE WITH A U...DAKSHIN BIHAR GRAMIN BANK: REDEFINING THE DIGITAL BANKING EXPERIENCE WITH A U...
DAKSHIN BIHAR GRAMIN BANK: REDEFINING THE DIGITAL BANKING EXPERIENCE WITH A U...
 
原版1:1定制堪培拉大学毕业证(UC毕业证)#文凭成绩单#真实留信学历认证永久存档
原版1:1定制堪培拉大学毕业证(UC毕业证)#文凭成绩单#真实留信学历认证永久存档原版1:1定制堪培拉大学毕业证(UC毕业证)#文凭成绩单#真实留信学历认证永久存档
原版1:1定制堪培拉大学毕业证(UC毕业证)#文凭成绩单#真实留信学历认证永久存档
 
Unveiling the Future: Columbus, Ohio Condominiums Through the Lens of 3D Arch...
Unveiling the Future: Columbus, Ohio Condominiums Through the Lens of 3D Arch...Unveiling the Future: Columbus, Ohio Condominiums Through the Lens of 3D Arch...
Unveiling the Future: Columbus, Ohio Condominiums Through the Lens of 3D Arch...
 
MT. Marseille an Archipelago. Strategies for Integrating Residential Communit...
MT. Marseille an Archipelago. Strategies for Integrating Residential Communit...MT. Marseille an Archipelago. Strategies for Integrating Residential Communit...
MT. Marseille an Archipelago. Strategies for Integrating Residential Communit...
 
How to Empower the future of UX Design with Gen AI
How to Empower the future of UX Design with Gen AIHow to Empower the future of UX Design with Gen AI
How to Empower the future of UX Design with Gen AI
 
Iconic Global Solution - web design, Digital Marketing services
Iconic Global Solution - web design, Digital Marketing servicesIconic Global Solution - web design, Digital Marketing services
Iconic Global Solution - web design, Digital Marketing services
 
Design and Managing Service in the field of tourism and hospitality industry
Design and Managing Service in the field of tourism and hospitality industryDesign and Managing Service in the field of tourism and hospitality industry
Design and Managing Service in the field of tourism and hospitality industry
 
Dubai Calls Girl Tapes O525547819 Real Tapes Escort Services Dubai
Dubai Calls Girl Tapes O525547819 Real Tapes Escort Services DubaiDubai Calls Girl Tapes O525547819 Real Tapes Escort Services Dubai
Dubai Calls Girl Tapes O525547819 Real Tapes Escort Services Dubai
 
cda.pptx critical discourse analysis ppt
cda.pptx critical discourse analysis pptcda.pptx critical discourse analysis ppt
cda.pptx critical discourse analysis ppt
 
Call Girls Meghani Nagar 7397865700 Independent Call Girls
Call Girls Meghani Nagar 7397865700  Independent Call GirlsCall Girls Meghani Nagar 7397865700  Independent Call Girls
Call Girls Meghani Nagar 7397865700 Independent Call Girls
 
PORTFOLIO DE ARQUITECTURA CRISTOBAL HERAUD 2024
PORTFOLIO DE ARQUITECTURA CRISTOBAL HERAUD 2024PORTFOLIO DE ARQUITECTURA CRISTOBAL HERAUD 2024
PORTFOLIO DE ARQUITECTURA CRISTOBAL HERAUD 2024
 
FiveHypotheses_UIDMasterclass_18April2024.pdf
FiveHypotheses_UIDMasterclass_18April2024.pdfFiveHypotheses_UIDMasterclass_18April2024.pdf
FiveHypotheses_UIDMasterclass_18April2024.pdf
 
ARt app | UX Case Study
ARt app | UX Case StudyARt app | UX Case Study
ARt app | UX Case Study
 
在线办理ohio毕业证俄亥俄大学毕业证成绩单留信学历认证
在线办理ohio毕业证俄亥俄大学毕业证成绩单留信学历认证在线办理ohio毕业证俄亥俄大学毕业证成绩单留信学历认证
在线办理ohio毕业证俄亥俄大学毕业证成绩单留信学历认证
 
办理卡尔顿大学毕业证成绩单|购买加拿大文凭证书
办理卡尔顿大学毕业证成绩单|购买加拿大文凭证书办理卡尔顿大学毕业证成绩单|购买加拿大文凭证书
办理卡尔顿大学毕业证成绩单|购买加拿大文凭证书
 
2024新版美国旧金山州立大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
2024新版美国旧金山州立大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree2024新版美国旧金山州立大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
2024新版美国旧金山州立大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
 
Passbook project document_april_21__.pdf
Passbook project document_april_21__.pdfPassbook project document_april_21__.pdf
Passbook project document_april_21__.pdf
 
原版美国亚利桑那州立大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
原版美国亚利桑那州立大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree原版美国亚利桑那州立大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
原版美国亚利桑那州立大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
 
8377877756 Full Enjoy @24/7 Call Girls in Nirman Vihar Delhi NCR
8377877756 Full Enjoy @24/7 Call Girls in Nirman Vihar Delhi NCR8377877756 Full Enjoy @24/7 Call Girls in Nirman Vihar Delhi NCR
8377877756 Full Enjoy @24/7 Call Girls in Nirman Vihar Delhi NCR
 
Call Girls in Ashok Nagar Delhi ✡️9711147426✡️ Escorts Service
Call Girls in Ashok Nagar Delhi ✡️9711147426✡️ Escorts ServiceCall Girls in Ashok Nagar Delhi ✡️9711147426✡️ Escorts Service
Call Girls in Ashok Nagar Delhi ✡️9711147426✡️ Escorts Service
 

unit 1 (1).pptx

  • 2. What Is Automation Testing?  Automation Testing is a technique using an automation tool to write and execute tester's test scripts and cases..  The testing tool takes actual outcomes and compares it with the expected result to generate detailed test reports.
  • 3.  Since test automation demands a considerable investment of resources and money,  We should define: 1. when to do automation, 2. the scope of the automation 3. best tool of automation.  Good planning practices can save us from high costs.
  • 4. In the automation process, steps involved are 1. Selecting the Test tool 2. Define scope of automation 3. Planning, design, and development 4. Test execution 5. Maintenance
  • 5.  Testing is an essential part of product development, especially to guarantee quality.  Many smaller and mid-sized companies don’t give testing much attention even though it’s essential for delivering a strong product.  Some companies prefer to do manual testing, although that’s not the only best approach.
  • 6.  The next logical step is automating your testing process.  Manual testing should be minimized at all costs.  Test automation increases overall software development efficiency and allows for more robust tools to be built.
  • 7. Benefits  Faster Feedback Cycle  Saves Time  Reduced Business Expenses  Higher Test Coverage  Reusability of Test Suite  Faster Time to Market  Improved Accuracy  Less Stress on QA Team  Quick Determination the Stability of Your Build  Eliminate Human Error
  • 8. Benefits  Ability To Perform Testing On Multiple Platforms In Parallel  Accelerate Cross Browser Testing  Distributed Test Execution  Data Driven Testing
  • 9. Most popular tools for automation testing  The most popular test tool for automation testing are • QTP (HP UFT) • Rational Robot • Selenium
  • 10. Why JUnit?  JUnit is one of the most popular unit testing frameworks for Java development.  Unit testing is an important part in Test Driven Development (TDD) as it helps finding problems in the code as early as possible, especially when you make changes to the existing code you can run unit tests again to make sure that the changes do not break the application (regression).  JUnit is supported by almost any Java IDEs and build tools, thus it is the default choice of programmers to test their code.  Eclipse has very good support for JUnit - the IDE is shipped with JUnit as its default testing library.  Thus writing and running unit tests with JUnit in Eclipse is quick, easy and productive.
  • 11. Structure of a Test Class This Calculator class has two methods add() and subtract(). Now we want to write a test class to ensure that these methods are working correctly. With JUnit, the test class can have the following structure:
  • 12.
  • 13. Annotations used in this test class  @BeforeClass:  Code in this method is executed only once, before all test methods in the test class. Typically you put code that prepares test environment here, e.g. initializing resources such as opening a database connection. The method marked with this annotation must be static.   @Before:  Code in this method is executed before every test method in the test class. So typically you put repeated code that must be executed before each test method here. 
  • 14.  @Test:  This annotation specifies the annotated method is a test method. You can notice the naming convention for test method is the method name starts with test, followed by the name of the method in the class being tested. This Calculator class has two methods add() and subtract(), hence the test methods are testAdd() and testSubtract().  @After:  Code in this method is executed after every test method in the test class. So typically you put repeated code that must be executed after each test method here. NOTE: The above-mentioned annotations are in JUnit 4.
  • 15.  @AfterClass:  Code in this method is executed only once, after all test methods in the test class. Due to this behavior, you can put code to clean up test environment here, e.g. closing the database connection. Note that this kind of method must be static.  Except the test methods, the other kinds of method are optional. So you implement them in the test class only if it is necessary.
  • 16. JUnit 5 changes in annotations  From JUnit 5,  @BeforeClass changes to @BeforeAll;  @Before changes to @BeforeEach;  @After changes to @AfterEach;  @AfterClass changes to @AfterAll.  This change in JUnit 5 reflects better meaning of the annotations.
  • 17. With JUnit 5, the structure of a test class looks like this:
  • 18. To be noted:  In JUnit 4, you need to import the annotations from the org.junit package, but in JUnit 5 you need to import them from the org.junit.jupiter.api package.
  • 19. Using Assert Statement in Test Methods  In a test method, we use an assert statement to verify whether the code under test produces the result as expected or not.  If the result is as expected, the tested code passes the test case. Otherwise the tested code fails the test case.
  • 20.  We use the assertEquals() method from the class org.junit.Assert via static import:  you can use the fail() method to fail the test immediately, for example: Use the fail() method to indicate that a method is not yet implemented so when the test class is executed, it will fail.
  • 21.  The assertEquals() method compares two values: the expected result and the actual value returned from the tested code.  If the two values are equal, the method returns normally indicating the tested code passes the test case.  If the two values are not equal, the method throws java.lang.AssertionError indicating the tested code fails the test case.  And programmers must fix the code until it passes the test case.
  • 22. JUnit provides many assert()methods, and here are some commonly used ones: • assertEquals(expected, actual): asserts that two values are equal. The values can be of any primitive types or Objects. • assertNotEquals(expected, actual): asserts that two arguments are not equal. The values can be of any primitive types or Object. • assertTrue(boolean condition): asserts that a condition is true. • assertFalse(boolean condition): asserts that a condition is false. • assertNull(Object): asserts that an object is null. • assertNotNull(Object): asserts that an object is not null. • assertSame(Object expected, Object actual): asserts that two objects refer to the same object. • assertNotSame(Object unexpected, Object actual): asserts that two objects do not refer to the same object.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29. You can see the green indicator bar in the upper-right corner indicating that the test case has been executed successfully - the code under test passes the test case.
  • 30. If the test fails, the status indicator becomes red and the failure trace is printed:
  • 31. This is the result of running the testSubtract() method,
  • 32. The class Calculator passes two test methods in the CalculatorTest class.