SlideShare a Scribd company logo
1 of 12
Unit and Functional Testing with
JUnit and Related Tools
Introduction
●
Testing
●
JUnit, etc.
Types of Testing
●
Unit testing: Does a single object work?
●
Integration testing: Do multiple objects work together?
●
Functional testing: Does my application work?
●
Performance testing: Does my application work well?
●
Acceptance testing: Does the customer like my
application?
Why Test?
●
No-brainers: Functional, Acceptance, Performance testing
●
Why Unit Test?
– Coverage, especially of strange conditions
– Facilitates teamwork, lessens 'ownership'
– Confidence in your own work
– Enable refactoring
– Self-documentation of API
– Improve design
How to use tests
●
A common testing cycle:
– Write some new code OR Fix a bug OR Refactor
some code
– Run tests to ensure the now-changed code works
– Check the new code in
Basic testing principles
●
For things that can be tested automatically, tests
should be:
– easy to write
– easy to run
– objective (easy to see if they pass or fail)
– repeatable (deterministic)
Writing tests
Methods of Junit.gramework.assert class
●
assertTrue(boolean)
●
You can supply any boolean expression to this method, and as long as the boolean expression
evaluates to true, the method reports success. If the condition you want to check should be false,
simply prepend the "!" negation operator to your parenthesized expression.
●
assertTrue(String, boolean)
●
Same as the first form of assertTrue, except that the supplied String is printed if the assertion fails.
Most methods have a version of this form with a message string.
●
assertEquals(Object, Object)
●
Compares the two objects you pass in using the equals( ) method.
●
assertNull(Object)
●
Succeeds if the Object reference passed in is null. There is also an assertNotNull method.
●
fail(String)
●
Causes the test to fail, printing out the supplied String.
JUnit
●
Open source framework for testing Java code
●
Attempts to make writing unit tests easy
●
Structure:
●
TestCase [Java class]
– Test [Java method]
– Most often you write TestCase
Example
import junit.framework.TestCase;
public class TestString extends TestCase {
public void testEndsWith() {
assertTrue(“abcabc”.endsWith(“abc”));
}
public void testEndsWithEmptyString() {
assertTrue(“Doesn't end with empty string!”,
“abcabc”.endsWith(“”));
}
}
Some best practices
●
TestCases (Java classes)
– Usually test a single Java class
– Name starts or ends with Test
●
Tests (Java methods)
– test a single method
●
testXxx tests method xxx
●
multiple tests of method xxx are named testXxxYyy,
where Yyy describes a particular condition, e.g.,
testEndsWithEmpty
●
Label your assertions
●
One test per test method
More details
●
fixtures: setUp, tearDown
●
assertFalse, assertEquals, assertNotEquals,
assertNull, etc., etc.
●
JUnit 4/Java 5 – some incremental improvements
Running JUnit tests
●
Many ways:
– Command line
– IDE (Eclipse plug-in, etc.)
– Ant
– Maven
●
Various ways of viewing output (text, XML ->
Web page, ...)

More Related Content

What's hot

How and what to unit test
How and what to unit testHow and what to unit test
How and what to unit testEugenio Lentini
 
Unit Testing Using N Unit
Unit Testing Using N UnitUnit Testing Using N Unit
Unit Testing Using N UnitGaurav Arora
 
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...Thomas Weller
 
Beginners - Get Started With Unit Testing in .NET
Beginners - Get Started With Unit Testing in .NETBeginners - Get Started With Unit Testing in .NET
Beginners - Get Started With Unit Testing in .NETBaskar K
 
New Features Of Test Unit 2.x
New Features Of Test Unit 2.xNew Features Of Test Unit 2.x
New Features Of Test Unit 2.xdjberg96
 
Swift testing ftw
Swift testing ftwSwift testing ftw
Swift testing ftwJorge Ortiz
 
Nguyenvandungb seminar
Nguyenvandungb seminarNguyenvandungb seminar
Nguyenvandungb seminardunglinh111
 
TDD - survival guide
TDD - survival guide TDD - survival guide
TDD - survival guide vitalipe
 
Automated testing of ASP .Net Core applications
Automated testing of ASP .Net Core applications Automated testing of ASP .Net Core applications
Automated testing of ASP .Net Core applications nispas
 
Moq presentation
Moq presentationMoq presentation
Moq presentationLynxStar
 
NUnit Features Presentation
NUnit Features PresentationNUnit Features Presentation
NUnit Features PresentationShir Brass
 
DIG1108C Lesson 7 Fall 2014
DIG1108C Lesson 7 Fall 2014DIG1108C Lesson 7 Fall 2014
DIG1108C Lesson 7 Fall 2014David Wolfpaw
 
Workshop: Unit Testing in Python
Workshop: Unit Testing in PythonWorkshop: Unit Testing in Python
Workshop: Unit Testing in PythonDavid Tan
 
Unit tests & TDD
Unit tests & TDDUnit tests & TDD
Unit tests & TDDDror Helper
 

What's hot (20)

How and what to unit test
How and what to unit testHow and what to unit test
How and what to unit test
 
Angular Unit Testing
Angular Unit TestingAngular Unit Testing
Angular Unit Testing
 
Workshop unit test
Workshop   unit testWorkshop   unit test
Workshop unit test
 
Unit Testing Using N Unit
Unit Testing Using N UnitUnit Testing Using N Unit
Unit Testing Using N Unit
 
AspectMock
AspectMockAspectMock
AspectMock
 
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
 
Beginners - Get Started With Unit Testing in .NET
Beginners - Get Started With Unit Testing in .NETBeginners - Get Started With Unit Testing in .NET
Beginners - Get Started With Unit Testing in .NET
 
New Features Of Test Unit 2.x
New Features Of Test Unit 2.xNew Features Of Test Unit 2.x
New Features Of Test Unit 2.x
 
Branching by abstraction
Branching by abstractionBranching by abstraction
Branching by abstraction
 
Swift testing ftw
Swift testing ftwSwift testing ftw
Swift testing ftw
 
Nguyenvandungb seminar
Nguyenvandungb seminarNguyenvandungb seminar
Nguyenvandungb seminar
 
TDD - survival guide
TDD - survival guide TDD - survival guide
TDD - survival guide
 
Nunit
NunitNunit
Nunit
 
Automated testing of ASP .Net Core applications
Automated testing of ASP .Net Core applications Automated testing of ASP .Net Core applications
Automated testing of ASP .Net Core applications
 
Moq presentation
Moq presentationMoq presentation
Moq presentation
 
NUnit Features Presentation
NUnit Features PresentationNUnit Features Presentation
NUnit Features Presentation
 
Tdd & unit test
Tdd & unit testTdd & unit test
Tdd & unit test
 
DIG1108C Lesson 7 Fall 2014
DIG1108C Lesson 7 Fall 2014DIG1108C Lesson 7 Fall 2014
DIG1108C Lesson 7 Fall 2014
 
Workshop: Unit Testing in Python
Workshop: Unit Testing in PythonWorkshop: Unit Testing in Python
Workshop: Unit Testing in Python
 
Unit tests & TDD
Unit tests & TDDUnit tests & TDD
Unit tests & TDD
 

Viewers also liked

MCC2기_풋풋요가 슬라이드
MCC2기_풋풋요가 슬라이드MCC2기_풋풋요가 슬라이드
MCC2기_풋풋요가 슬라이드mcc2nd
 
Adjusting Document Margins
Adjusting Document MarginsAdjusting Document Margins
Adjusting Document Marginscbuzz001
 
Action Weekly_april_2015
Action Weekly_april_2015Action Weekly_april_2015
Action Weekly_april_2015inactionagency
 
AEM 5.6.1 e-Commerce Integration by Meryll Blanchet
AEM 5.6.1 e-Commerce Integration by Meryll BlanchetAEM 5.6.1 e-Commerce Integration by Meryll Blanchet
AEM 5.6.1 e-Commerce Integration by Meryll BlanchetAEM HUB
 
البلاغة و الأسلوب
البلاغة و الأسلوبالبلاغة و الأسلوب
البلاغة و الأسلوبsayyid4212
 
(N)one Click Deployment by Joerg Hoh
(N)one Click Deployment by Joerg Hoh(N)one Click Deployment by Joerg Hoh
(N)one Click Deployment by Joerg HohAEM HUB
 
PHP Course in Kolkata
PHP Course in KolkataPHP Course in Kolkata
PHP Course in KolkataEjobIndia
 
Socialize your Exceptional Web Experience – Adobe AEM & IBM Connections by He...
Socialize your Exceptional Web Experience – Adobe AEM & IBM Connections by He...Socialize your Exceptional Web Experience – Adobe AEM & IBM Connections by He...
Socialize your Exceptional Web Experience – Adobe AEM & IBM Connections by He...AEM HUB
 
Action weekly'15 edition 1
Action weekly'15 edition 1Action weekly'15 edition 1
Action weekly'15 edition 1inactionagency
 

Viewers also liked (14)

MCC2기_풋풋요가 슬라이드
MCC2기_풋풋요가 슬라이드MCC2기_풋풋요가 슬라이드
MCC2기_풋풋요가 슬라이드
 
Action Weekly ver.9
Action Weekly ver.9Action Weekly ver.9
Action Weekly ver.9
 
Adjusting Document Margins
Adjusting Document MarginsAdjusting Document Margins
Adjusting Document Margins
 
Veerendra_2016_V2
Veerendra_2016_V2Veerendra_2016_V2
Veerendra_2016_V2
 
Action weekly ver.6
Action weekly ver.6Action weekly ver.6
Action weekly ver.6
 
Action Weekly_april_2015
Action Weekly_april_2015Action Weekly_april_2015
Action Weekly_april_2015
 
AEM 5.6.1 e-Commerce Integration by Meryll Blanchet
AEM 5.6.1 e-Commerce Integration by Meryll BlanchetAEM 5.6.1 e-Commerce Integration by Meryll Blanchet
AEM 5.6.1 e-Commerce Integration by Meryll Blanchet
 
البلاغة و الأسلوب
البلاغة و الأسلوبالبلاغة و الأسلوب
البلاغة و الأسلوب
 
(N)one Click Deployment by Joerg Hoh
(N)one Click Deployment by Joerg Hoh(N)one Click Deployment by Joerg Hoh
(N)one Click Deployment by Joerg Hoh
 
Plunder and Ruin
Plunder and Ruin
Plunder and Ruin
Plunder and Ruin
 
Cc sistemaslol
Cc sistemaslolCc sistemaslol
Cc sistemaslol
 
PHP Course in Kolkata
PHP Course in KolkataPHP Course in Kolkata
PHP Course in Kolkata
 
Socialize your Exceptional Web Experience – Adobe AEM & IBM Connections by He...
Socialize your Exceptional Web Experience – Adobe AEM & IBM Connections by He...Socialize your Exceptional Web Experience – Adobe AEM & IBM Connections by He...
Socialize your Exceptional Web Experience – Adobe AEM & IBM Connections by He...
 
Action weekly'15 edition 1
Action weekly'15 edition 1Action weekly'15 edition 1
Action weekly'15 edition 1
 

Similar to Intro to junit

SE2_Lec 21_ TDD and Junit
SE2_Lec 21_ TDD and JunitSE2_Lec 21_ TDD and Junit
SE2_Lec 21_ TDD and JunitAmr E. Mohamed
 
Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)Lars Thorup
 
Testing Spark and Scala
Testing Spark and ScalaTesting Spark and Scala
Testing Spark and Scaladatamantra
 
Software Testing
Software TestingSoftware Testing
Software TestingAdroitLogic
 
Unit Testing and TDD 2017
Unit Testing and TDD 2017Unit Testing and TDD 2017
Unit Testing and TDD 2017Xavi Hidalgo
 
J unit presentation
J unit presentationJ unit presentation
J unit presentationPriya Sharma
 
SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)Amr E. Mohamed
 
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017Ortus Solutions, Corp
 
DotNet unit testing training
DotNet unit testing trainingDotNet unit testing training
DotNet unit testing trainingTom Tang
 

Similar to Intro to junit (20)

SE2_Lec 21_ TDD and Junit
SE2_Lec 21_ TDD and JunitSE2_Lec 21_ TDD and Junit
SE2_Lec 21_ TDD and Junit
 
Junit
JunitJunit
Junit
 
Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)
 
Testing Spark and Scala
Testing Spark and ScalaTesting Spark and Scala
Testing Spark and Scala
 
Software Testing
Software TestingSoftware Testing
Software Testing
 
Why Unit Testingl
Why Unit TestinglWhy Unit Testingl
Why Unit Testingl
 
Why unit testingl
Why unit testinglWhy unit testingl
Why unit testingl
 
Why Unit Testingl
Why Unit TestinglWhy Unit Testingl
Why Unit Testingl
 
Unit Testing in Java
Unit Testing in JavaUnit Testing in Java
Unit Testing in Java
 
Unit testing
Unit testingUnit testing
Unit testing
 
Unit Testing and TDD 2017
Unit Testing and TDD 2017Unit Testing and TDD 2017
Unit Testing and TDD 2017
 
J unit presentation
J unit presentationJ unit presentation
J unit presentation
 
JUnit Presentation
JUnit PresentationJUnit Presentation
JUnit Presentation
 
SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Unit testing
Unit testingUnit testing
Unit testing
 
Junit 4.0
Junit 4.0Junit 4.0
Junit 4.0
 
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
 
DotNet unit testing training
DotNet unit testing trainingDotNet unit testing training
DotNet unit testing training
 
Unit testing (eng)
Unit testing (eng)Unit testing (eng)
Unit testing (eng)
 

Recently uploaded

SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 

Recently uploaded (20)

SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 

Intro to junit

  • 1. Unit and Functional Testing with JUnit and Related Tools
  • 3. Types of Testing ● Unit testing: Does a single object work? ● Integration testing: Do multiple objects work together? ● Functional testing: Does my application work? ● Performance testing: Does my application work well? ● Acceptance testing: Does the customer like my application?
  • 4. Why Test? ● No-brainers: Functional, Acceptance, Performance testing ● Why Unit Test? – Coverage, especially of strange conditions – Facilitates teamwork, lessens 'ownership' – Confidence in your own work – Enable refactoring – Self-documentation of API – Improve design
  • 5. How to use tests ● A common testing cycle: – Write some new code OR Fix a bug OR Refactor some code – Run tests to ensure the now-changed code works – Check the new code in
  • 6. Basic testing principles ● For things that can be tested automatically, tests should be: – easy to write – easy to run – objective (easy to see if they pass or fail) – repeatable (deterministic)
  • 7. Writing tests Methods of Junit.gramework.assert class ● assertTrue(boolean) ● You can supply any boolean expression to this method, and as long as the boolean expression evaluates to true, the method reports success. If the condition you want to check should be false, simply prepend the "!" negation operator to your parenthesized expression. ● assertTrue(String, boolean) ● Same as the first form of assertTrue, except that the supplied String is printed if the assertion fails. Most methods have a version of this form with a message string. ● assertEquals(Object, Object) ● Compares the two objects you pass in using the equals( ) method. ● assertNull(Object) ● Succeeds if the Object reference passed in is null. There is also an assertNotNull method. ● fail(String) ● Causes the test to fail, printing out the supplied String.
  • 8. JUnit ● Open source framework for testing Java code ● Attempts to make writing unit tests easy ● Structure: ● TestCase [Java class] – Test [Java method] – Most often you write TestCase
  • 9. Example import junit.framework.TestCase; public class TestString extends TestCase { public void testEndsWith() { assertTrue(“abcabc”.endsWith(“abc”)); } public void testEndsWithEmptyString() { assertTrue(“Doesn't end with empty string!”, “abcabc”.endsWith(“”)); } }
  • 10. Some best practices ● TestCases (Java classes) – Usually test a single Java class – Name starts or ends with Test ● Tests (Java methods) – test a single method ● testXxx tests method xxx ● multiple tests of method xxx are named testXxxYyy, where Yyy describes a particular condition, e.g., testEndsWithEmpty ● Label your assertions ● One test per test method
  • 11. More details ● fixtures: setUp, tearDown ● assertFalse, assertEquals, assertNotEquals, assertNull, etc., etc. ● JUnit 4/Java 5 – some incremental improvements
  • 12. Running JUnit tests ● Many ways: – Command line – IDE (Eclipse plug-in, etc.) – Ant – Maven ● Various ways of viewing output (text, XML -> Web page, ...)