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

PPTX
Renaissance of JUnit - Introduction to JUnit 5
PDF
Write unit test from scratch
PDF
Unit testing in swift 2 - The before & after story
PDF
JenkinsPy workshop
PDF
Funcargs & other fun with pytest
PDF
QBR q2 2015
PDF
programme JP_version 7
PPTX
Lobby ppt monday 1st june
Renaissance of JUnit - Introduction to JUnit 5
Write unit test from scratch
Unit testing in swift 2 - The before & after story
JenkinsPy workshop
Funcargs & other fun with pytest
QBR q2 2015
programme JP_version 7
Lobby ppt monday 1st june

Viewers also liked (8)

PPTX
Game online
PDF
QBR q4 2011 Trophy
PDF
Best system and process
PDF
Best sellout e-ABM trophy
PPT
птицы весной
PDF
slides
DOCX
Louise Cover Letter
PPT
Opistorkhoz Гасанов
Game online
QBR q4 2011 Trophy
Best system and process
Best sellout e-ABM trophy
птицы весной
slides
Louise Cover Letter
Opistorkhoz Гасанов
Ad

Similar to Junit (20)

PPTX
Testing with Spring, AOT, GraalVM, and JUnit 5 - Spring I/O 2023
PDF
JUnit5 Custom TestEngines intro - version 2020-06
ODP
Test ng
PPTX
Unit testing
PPTX
Test NG Framework Complete Walk Through
PDF
Testing with JUnit 5 and Spring
PDF
Maven and j unit introduction
DOCX
JUnit_Guide_Expanded_Presentation[1].docx
DOCX
JUnit_Guide_Expanded_Presentation[1].docx............................
DOCX
JUnit_Guide_Expanded_Presentation[1].docx
PDF
L08 Unit Testing
PDF
Testing with JUnit 5 and Spring - Spring I/O 2022
PDF
An Introduction to JUnit 5 and how to use it with Spring boot tests and Mockito
PDF
JUnit is a Regression Testing Framework used by developers to implem.pdf
PDF
Unit testing in Unity
PDF
Impact Testing
PDF
Developing Selenium tests with JUnit 5
ODP
Advanced junit and mockito
PPTX
JUnit Test Case With Processminer modules.pptx
PDF
Unit testing (eng)
Testing with Spring, AOT, GraalVM, and JUnit 5 - Spring I/O 2023
JUnit5 Custom TestEngines intro - version 2020-06
Test ng
Unit testing
Test NG Framework Complete Walk Through
Testing with JUnit 5 and Spring
Maven and j unit introduction
JUnit_Guide_Expanded_Presentation[1].docx
JUnit_Guide_Expanded_Presentation[1].docx............................
JUnit_Guide_Expanded_Presentation[1].docx
L08 Unit Testing
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
JUnit is a Regression Testing Framework used by developers to implem.pdf
Unit testing in Unity
Impact Testing
Developing Selenium tests with JUnit 5
Advanced junit and mockito
JUnit Test Case With Processminer modules.pptx
Unit testing (eng)
Ad

More from fbenault (12)

ODP
Bdd java
ODP
Property based-testing
ODP
Java concurrency
ODP
Assertj-DB
ODP
Introduction to the language R
ODP
Assertj-core
ODP
System rules
ODP
Db in-memory
ODP
DbSetup
ODP
Guava
ODP
Java8
ODP
Easymock
Bdd java
Property based-testing
Java concurrency
Assertj-DB
Introduction to the language R
Assertj-core
System rules
Db in-memory
DbSetup
Guava
Java8
Easymock

Recently uploaded (20)

PPTX
Introduction to cybersecurity and digital nettiquette
PPTX
Digital Literacy And Online Safety on internet
PDF
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
PPTX
presentation_pfe-universite-molay-seltan.pptx
PPT
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
PPTX
artificialintelligenceai1-copy-210604123353.pptx
PPTX
Database Information System - Management Information System
PPT
FIRE PREVENTION AND CONTROL PLAN- LUS.FM.MQ.OM.UTM.PLN.00014.ppt
PPTX
newyork.pptxirantrafgshenepalchinachinane
PDF
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...
DOCX
Unit-3 cyber security network security of internet system
PDF
Smart Home Technology for Health Monitoring (www.kiu.ac.ug)
PDF
SASE Traffic Flow - ZTNA Connector-1.pdf
PPTX
E -tech empowerment technologies PowerPoint
PDF
Exploring VPS Hosting Trends for SMBs in 2025
PPTX
Internet___Basics___Styled_ presentation
PPTX
t_and_OpenAI_Combined_two_pressentations
PDF
💰 𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓 💰
PPT
415456121-Jiwratrwecdtwfdsfwgdwedvwe dbwsdjsadca-EVN.ppt
PPTX
INTERNET------BASICS-------UPDATED PPT PRESENTATION
Introduction to cybersecurity and digital nettiquette
Digital Literacy And Online Safety on internet
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
presentation_pfe-universite-molay-seltan.pptx
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
artificialintelligenceai1-copy-210604123353.pptx
Database Information System - Management Information System
FIRE PREVENTION AND CONTROL PLAN- LUS.FM.MQ.OM.UTM.PLN.00014.ppt
newyork.pptxirantrafgshenepalchinachinane
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...
Unit-3 cyber security network security of internet system
Smart Home Technology for Health Monitoring (www.kiu.ac.ug)
SASE Traffic Flow - ZTNA Connector-1.pdf
E -tech empowerment technologies PowerPoint
Exploring VPS Hosting Trends for SMBs in 2025
Internet___Basics___Styled_ presentation
t_and_OpenAI_Combined_two_pressentations
💰 𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓 💰
415456121-Jiwratrwecdtwfdsfwgdwedvwe dbwsdjsadca-EVN.ppt
INTERNET------BASICS-------UPDATED PPT PRESENTATION

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