SlideShare a Scribd company logo
Junit
By Franck Benault
Created 02/06/2015
Last update 13/07/2016
Junit introduction
● Samples in Github
– https://github.com/franck-benault/test-junit
● Junit is the most common tests framework for the java
language
● Based on annotations since version 4
● Tests organisation
● First assertion
● We often need other frameworks to write complete and
efficient tests
JUnit plan
Junit integration
● Plugin installed by default in Eclipse
● Integrated in Maven
● You could mixed tests with Junit and tests with TestNG
Junit tests regroupment
● Regroupment per class
– @Suite
● Regroupment per test
– @Category
● Still in « experimental » package
Junit assertions
● AssertArrayEquals
● AssertEquals / assertNotEquals
● AssertTrue / assertFalse
● AssertNull / assertNotNull
● AssertSame / assertNotSame
● AssertThat (hamcrest)
Junit assertions samples
● AssertArrayEquals
– private int[] ints1 = {1,3};
– private int[] ints2 = {1,3};
– .../...
– assertArrayEquals(ints1, ints2);
– assertArrayEquals("explanation",ints1, ints2);
Junit rules
● Rules allow very flexible addition or redifinition of the
behavior of each test method in a test class.
● Tester can reuse or extend one of the provided Rules
(example system-rules a library of rules)
● Main rules
– TemporaryFolder rule
– ExternalResource rule
– Timeout rule
Temporary rules
● The temporaryFolder rule allows
– Creation of files
– Creation of folder
– Deletion of them when the test method finishes
@Rule
public TemporaryFolder folder = new TemporaryFolder();
Handling exceptions
● Fail with try-catch bloc
● @Test annotation
● Junit rule
● Catch-exception library
● Write its own annotation
Conclusion
● Junit is essential to write tests with de Java language
● There are a lot of additional frameworks which complete
Junit
Around Junit

More Related Content

Viewers also liked

QBR q4 2011 Trophy
QBR q4 2011 TrophyQBR q4 2011 Trophy
QBR q4 2011 TrophyRahul Som
 
Best system and process
Best system and processBest system and process
Best system and processRahul Som
 
Best sellout e-ABM trophy
Best sellout e-ABM trophyBest sellout e-ABM trophy
Best sellout e-ABM trophyRahul Som
 
птицы весной
птицы веснойптицы весной
птицы веснойredkina
 
Opistorkhoz Гасанов
Opistorkhoz ГасановOpistorkhoz Гасанов
Opistorkhoz ГасановGasanovArif
 

Viewers also liked (8)

Game online
Game onlineGame online
Game online
 
QBR q4 2011 Trophy
QBR q4 2011 TrophyQBR q4 2011 Trophy
QBR q4 2011 Trophy
 
Best system and process
Best system and processBest system and process
Best system and process
 
Best sellout e-ABM trophy
Best sellout e-ABM trophyBest sellout e-ABM trophy
Best sellout e-ABM trophy
 
птицы весной
птицы веснойптицы весной
птицы весной
 
slides
slidesslides
slides
 
Louise Cover Letter
Louise Cover LetterLouise Cover Letter
Louise Cover Letter
 
Opistorkhoz Гасанов
Opistorkhoz ГасановOpistorkhoz Гасанов
Opistorkhoz Гасанов
 

Similar to Junit

Testing with Spring, AOT, GraalVM, and JUnit 5 - Spring I/O 2023
Testing with Spring, AOT, GraalVM, and JUnit 5 - Spring I/O 2023Testing with Spring, AOT, GraalVM, and JUnit 5 - Spring I/O 2023
Testing with Spring, AOT, GraalVM, and JUnit 5 - Spring I/O 2023Sam Brannen
 
JUnit5 Custom TestEngines intro - version 2020-06
JUnit5 Custom TestEngines intro - version 2020-06JUnit5 Custom TestEngines intro - version 2020-06
JUnit5 Custom TestEngines intro - version 2020-06Sven Ruppert
 
Testing with JUnit 5 and Spring
Testing with JUnit 5 and SpringTesting with JUnit 5 and Spring
Testing with JUnit 5 and SpringVMware Tanzu
 
Maven and j unit introduction
Maven and j unit introductionMaven and j unit introduction
Maven and j unit introductionSergii Fesenko
 
Testing your puppet code
Testing your puppet codeTesting your puppet code
Testing your puppet codeJulien Pivotto
 
Testing with JUnit 5 and Spring - Spring I/O 2022
Testing with JUnit 5 and Spring - Spring I/O 2022Testing with JUnit 5 and Spring - Spring I/O 2022
Testing with JUnit 5 and Spring - Spring I/O 2022Sam Brannen
 
An Introduction to JUnit 5 and how to use it with Spring boot tests and Mockito
An Introduction to JUnit 5 and how to use it with Spring boot tests and MockitoAn Introduction to JUnit 5 and how to use it with Spring boot tests and Mockito
An Introduction to JUnit 5 and how to use it with Spring boot tests and Mockitoshaunthomas999
 
JUnit is a Regression Testing Framework used by developers to implem.pdf
JUnit is a Regression Testing Framework used by developers to implem.pdfJUnit is a Regression Testing Framework used by developers to implem.pdf
JUnit is a Regression Testing Framework used by developers to implem.pdfaplolomedicalstoremr
 
Impact Testing
Impact TestingImpact Testing
Impact TestingRaquel Pau
 
Developing Selenium tests with JUnit 5
Developing Selenium tests with JUnit 5Developing Selenium tests with JUnit 5
Developing Selenium tests with JUnit 5Boni García
 
Advanced junit and mockito
Advanced junit and mockitoAdvanced junit and mockito
Advanced junit and mockitoMathieu Carbou
 
Testing Spark and Scala
Testing Spark and ScalaTesting Spark and Scala
Testing Spark and Scaladatamantra
 
JUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkJUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkOnkar Deshpande
 

Similar to Junit (20)

Testing with Spring, AOT, GraalVM, and JUnit 5 - Spring I/O 2023
Testing with Spring, AOT, GraalVM, and JUnit 5 - Spring I/O 2023Testing with Spring, AOT, GraalVM, and JUnit 5 - Spring I/O 2023
Testing with Spring, AOT, GraalVM, and JUnit 5 - Spring I/O 2023
 
JUnit5 Custom TestEngines intro - version 2020-06
JUnit5 Custom TestEngines intro - version 2020-06JUnit5 Custom TestEngines intro - version 2020-06
JUnit5 Custom TestEngines intro - version 2020-06
 
Test ng
Test ngTest ng
Test ng
 
Unit testing
Unit testingUnit testing
Unit testing
 
Test NG Framework Complete Walk Through
Test NG Framework Complete Walk ThroughTest NG Framework Complete Walk Through
Test NG Framework Complete Walk Through
 
Testing with JUnit 5 and Spring
Testing with JUnit 5 and SpringTesting with JUnit 5 and Spring
Testing with JUnit 5 and Spring
 
Maven and j unit introduction
Maven and j unit introductionMaven and j unit introduction
Maven and j unit introduction
 
Testing your puppet code
Testing your puppet codeTesting your puppet code
Testing your puppet code
 
L08 Unit Testing
L08 Unit TestingL08 Unit Testing
L08 Unit Testing
 
Testing with JUnit 5 and Spring - Spring I/O 2022
Testing with JUnit 5 and Spring - Spring I/O 2022Testing with JUnit 5 and Spring - Spring I/O 2022
Testing with JUnit 5 and Spring - Spring I/O 2022
 
An Introduction to JUnit 5 and how to use it with Spring boot tests and Mockito
An Introduction to JUnit 5 and how to use it with Spring boot tests and MockitoAn Introduction to JUnit 5 and how to use it with Spring boot tests and Mockito
An Introduction to JUnit 5 and how to use it with Spring boot tests and Mockito
 
JUnit is a Regression Testing Framework used by developers to implem.pdf
JUnit is a Regression Testing Framework used by developers to implem.pdfJUnit is a Regression Testing Framework used by developers to implem.pdf
JUnit is a Regression Testing Framework used by developers to implem.pdf
 
Unit testing in Unity
Unit testing in UnityUnit testing in Unity
Unit testing in Unity
 
Impact Testing
Impact TestingImpact Testing
Impact Testing
 
Developing Selenium tests with JUnit 5
Developing Selenium tests with JUnit 5Developing Selenium tests with JUnit 5
Developing Selenium tests with JUnit 5
 
Advanced junit and mockito
Advanced junit and mockitoAdvanced junit and mockito
Advanced junit and mockito
 
Unit testing (eng)
Unit testing (eng)Unit testing (eng)
Unit testing (eng)
 
Testing Spark and Scala
Testing Spark and ScalaTesting Spark and Scala
Testing Spark and Scala
 
Pyunit
PyunitPyunit
Pyunit
 
JUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkJUnit- A Unit Testing Framework
JUnit- A Unit Testing Framework
 

More from fbenault

Property based-testing
Property based-testingProperty based-testing
Property based-testingfbenault
 
Java concurrency
Java concurrencyJava concurrency
Java concurrencyfbenault
 
Assertj-DB
Assertj-DBAssertj-DB
Assertj-DBfbenault
 
Introduction to the language R
Introduction to the language RIntroduction to the language R
Introduction to the language Rfbenault
 
Assertj-core
Assertj-coreAssertj-core
Assertj-corefbenault
 
System rules
System rulesSystem rules
System rulesfbenault
 
Db in-memory
Db in-memoryDb in-memory
Db in-memoryfbenault
 

More from fbenault (12)

Bdd java
Bdd javaBdd java
Bdd java
 
Property based-testing
Property based-testingProperty based-testing
Property based-testing
 
Java concurrency
Java concurrencyJava concurrency
Java concurrency
 
Assertj-DB
Assertj-DBAssertj-DB
Assertj-DB
 
Introduction to the language R
Introduction to the language RIntroduction to the language R
Introduction to the language R
 
Assertj-core
Assertj-coreAssertj-core
Assertj-core
 
System rules
System rulesSystem rules
System rules
 
Db in-memory
Db in-memoryDb in-memory
Db in-memory
 
DbSetup
DbSetupDbSetup
DbSetup
 
Guava
GuavaGuava
Guava
 
Java8
Java8Java8
Java8
 
Easymock
EasymockEasymock
Easymock
 

Recently uploaded

ER(Entity Relationship) Diagram for online shopping - TAE
ER(Entity Relationship) Diagram for online shopping - TAEER(Entity Relationship) Diagram for online shopping - TAE
ER(Entity Relationship) Diagram for online shopping - TAEHimani415946
 
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shopHistory+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shoplaozhuseo02
 
The+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptxThe+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptxlaozhuseo02
 
Pvtaan Social media marketing proposal.pdf
Pvtaan Social media marketing proposal.pdfPvtaan Social media marketing proposal.pdf
Pvtaan Social media marketing proposal.pdfPvtaan
 
The Use of AI in Indonesia Election 2024: A Case Study
The Use of AI in Indonesia Election 2024: A Case StudyThe Use of AI in Indonesia Election 2024: A Case Study
The Use of AI in Indonesia Election 2024: A Case StudyDamar Juniarto
 
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理aagad
 
How to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptxHow to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptxGal Baras
 
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and GuidelinesMulti-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and GuidelinesSanjeev Rampal
 
The AI Powered Organization-Intro to AI-LAN.pdf
The AI Powered Organization-Intro to AI-LAN.pdfThe AI Powered Organization-Intro to AI-LAN.pdf
The AI Powered Organization-Intro to AI-LAN.pdfSiskaFitrianingrum
 
Article writing on excessive use of internet.pptx
Article writing on excessive use of internet.pptxArticle writing on excessive use of internet.pptx
Article writing on excessive use of internet.pptxabhinandnam9997
 
How Do I Begin the Linksys Velop Setup Process?
How Do I Begin the Linksys Velop Setup Process?How Do I Begin the Linksys Velop Setup Process?
How Do I Begin the Linksys Velop Setup Process?Linksys Velop Login
 

Recently uploaded (12)

ER(Entity Relationship) Diagram for online shopping - TAE
ER(Entity Relationship) Diagram for online shopping - TAEER(Entity Relationship) Diagram for online shopping - TAE
ER(Entity Relationship) Diagram for online shopping - TAE
 
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shopHistory+of+E-commerce+Development+in+China-www.cfye-commerce.shop
History+of+E-commerce+Development+in+China-www.cfye-commerce.shop
 
The+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptxThe+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptx
 
Pvtaan Social media marketing proposal.pdf
Pvtaan Social media marketing proposal.pdfPvtaan Social media marketing proposal.pdf
Pvtaan Social media marketing proposal.pdf
 
The Use of AI in Indonesia Election 2024: A Case Study
The Use of AI in Indonesia Election 2024: A Case StudyThe Use of AI in Indonesia Election 2024: A Case Study
The Use of AI in Indonesia Election 2024: A Case Study
 
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
 
How to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptxHow to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptx
 
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and GuidelinesMulti-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
 
The AI Powered Organization-Intro to AI-LAN.pdf
The AI Powered Organization-Intro to AI-LAN.pdfThe AI Powered Organization-Intro to AI-LAN.pdf
The AI Powered Organization-Intro to AI-LAN.pdf
 
Article writing on excessive use of internet.pptx
Article writing on excessive use of internet.pptxArticle writing on excessive use of internet.pptx
Article writing on excessive use of internet.pptx
 
How Do I Begin the Linksys Velop Setup Process?
How Do I Begin the Linksys Velop Setup Process?How Do I Begin the Linksys Velop Setup Process?
How Do I Begin the Linksys Velop Setup Process?
 
The Best AI Powered Software - Intellivid AI Studio
The Best AI Powered Software - Intellivid AI StudioThe Best AI Powered Software - Intellivid AI Studio
The Best AI Powered Software - Intellivid AI Studio
 

Junit

  • 1. Junit By Franck Benault Created 02/06/2015 Last update 13/07/2016
  • 2. Junit introduction ● Samples in Github – https://github.com/franck-benault/test-junit ● Junit is the most common tests framework for the java language ● Based on annotations since version 4 ● Tests organisation ● First assertion ● We often need other frameworks to write complete and efficient tests
  • 4. Junit integration ● Plugin installed by default in Eclipse ● Integrated in Maven ● You could mixed tests with Junit and tests with TestNG
  • 5. Junit tests regroupment ● Regroupment per class – @Suite ● Regroupment per test – @Category ● Still in « experimental » package
  • 6. Junit assertions ● AssertArrayEquals ● AssertEquals / assertNotEquals ● AssertTrue / assertFalse ● AssertNull / assertNotNull ● AssertSame / assertNotSame ● AssertThat (hamcrest)
  • 7. Junit assertions samples ● AssertArrayEquals – private int[] ints1 = {1,3}; – private int[] ints2 = {1,3}; – .../... – assertArrayEquals(ints1, ints2); – assertArrayEquals("explanation",ints1, ints2);
  • 8. Junit rules ● Rules allow very flexible addition or redifinition of the behavior of each test method in a test class. ● Tester can reuse or extend one of the provided Rules (example system-rules a library of rules) ● Main rules – TemporaryFolder rule – ExternalResource rule – Timeout rule
  • 9. Temporary rules ● The temporaryFolder rule allows – Creation of files – Creation of folder – Deletion of them when the test method finishes @Rule public TemporaryFolder folder = new TemporaryFolder();
  • 10. Handling exceptions ● Fail with try-catch bloc ● @Test annotation ● Junit rule ● Catch-exception library ● Write its own annotation
  • 11. Conclusion ● Junit is essential to write tests with de Java language ● There are a lot of additional frameworks which complete Junit