SlideShare a Scribd company logo
1 of 47
Download to read offline
can it still teach us
something?
Andrzej Jóźwiak
andrzej.jozwiak@gmail.com
ajoz.github.io
https://github.com/artificialrevelations
4
meetup.juglodz.pl
yt.juglodz.pl
fb.juglodz.pl
use kariera-it-20 discount code to get 20% off
Empty Non-Empty
push
pop
push
new
getDepth = 0
isEmpty = true
p
e
e
k
p
o
p
Exception
getDepth = N*
isEmpty = false
An immutable
Stack, with two
distinct states
“So who should you be writing the
tests for? For the person trying to
understand your code. Good tests
act as documentation for the code
they are testing. They describe
how the code works.”
Gerard Meszaros
97 Things Every Programmer Should Know by Kevlin Henney
Given: there is no stack
When: a stack is created
Then: it is empty
Given: there is no stack
When: a stack is created
Then: it is has a depth of zero
Enclosed Runner
- Gives us only one level of nesting :-(
- Enclosed is a suite thus each inner static class can be run
with a different runner :-)
- Abstract inner classes are ignored thus adding an abstract
keyword can disable a test
- Shared setup (all the @Before and @After) needs to be
hidden inside an abstract class (which won’t be run)
- JUnit5 has a @Nested annotation that allows for deeper
nesting then a single level
ExpectedException Rule
- no explicit try/catch block
- it’s possible to expect an exception just before the point it
will happen, this avoids the situation where something else
throws a similar exception
- it’s possible to match part of the exception message
- deprecated in 4.13 :-(
- does not exist in JUnit 5.x :-(
- usage of Assert.assertThrows is encouraged
TemporaryFolder Rule
- allows creating a temporary directory structure, create
files, directories etc
- can recursively create directories
- Starting with version 4.13 allows strict verification of
deleted resources which fails the test with AssertionError if
resources cannot be deleted
- only in compatibility mode in JUnit 5 :-(
ExternalResource Rule
- Great example of such ExternalResource is
MockWebServer from okhttp
- Very useful for working with any kind of in memory
database
- Can help setup any form of dependency injection
- For sending information to some external service before
and after the test
- sky is the limit ;-)
RuleChain
- the ordering might be important for example if we have a
rule that starts the app and closes it at the end, so if we
want to do some screenshots of the running app we need
to run the screenshot rule before the app closing rule will
finish
- when ordering is the key
- when rules depend on each other
What we want?
- create a test that checks the depth after some amount of
operations performed on the stack
- specify the amount of push operations
- specify the amount of pop operations
- specify the expected depth of the stack
Parametrized
- ugly syntax :-( (JUnitParams library does this better)
- we can run @Before and @After like in a normal test
- we can have more than one test method but we need
assumptions to control the values that are fed to our test
- can easily grow in size
- we need to think about all the examples beforehand
Can we test general properties of our code without
giving specific examples?
https://github.com/artificialrevelations/teoria
Theories
- not supported in JUnit5 but property based testing as a
concept can be done through other libraries e.g. jqwik
- can have fixed data points
- can have multiple different sources of generated values
- should probably be under smoke test category
- are not easy to define properly
Good Properties
- business rules as a property
- using the same input will produce the same output
- applying functions that are inverse should result with the
initial state
- doing something multiple times won’t change the result
- some operations should not change other existing
properties of the tested code/structure/class e.g. sorting
won’t change the size, filtering won’t change the order
- sometimes order of operations won’t change the result e.g.
fiter(sort) == sort(filter)
Questions?

More Related Content

What's hot

Unit testing Ch. 13 of Programming Ruby
Unit testing Ch. 13 of Programming RubyUnit testing Ch. 13 of Programming Ruby
Unit testing Ch. 13 of Programming Rubylvrubygroup
 
unittest in 5 minutes
unittest in 5 minutesunittest in 5 minutes
unittest in 5 minutesRay Toal
 
Automated testing in Drupal
Automated testing in DrupalAutomated testing in Drupal
Automated testing in DrupalArtem Berdishev
 
Debugging NET Applications With WinDBG
Debugging  NET Applications With WinDBGDebugging  NET Applications With WinDBG
Debugging NET Applications With WinDBGCory Foy
 
Manage Selenium Grid with Terraform by Omkar Khatavkar (https://www.linkedin....
Manage Selenium Grid with Terraform by Omkar Khatavkar (https://www.linkedin....Manage Selenium Grid with Terraform by Omkar Khatavkar (https://www.linkedin....
Manage Selenium Grid with Terraform by Omkar Khatavkar (https://www.linkedin....Software Testing Board
 
Code Igniter Code Sniffer
Code Igniter  Code SnifferCode Igniter  Code Sniffer
Code Igniter Code SnifferAlbert Rosa
 
20140408 tdd puppetcamp-paris
20140408 tdd puppetcamp-paris20140408 tdd puppetcamp-paris
20140408 tdd puppetcamp-parisJohan De Wit
 
Successful Joomla migrations that don't hurt Search Engine Rankings
Successful Joomla migrations that don't hurt Search Engine RankingsSuccessful Joomla migrations that don't hurt Search Engine Rankings
Successful Joomla migrations that don't hurt Search Engine RankingsJoomla Day South Africa
 
Python Testing Fundamentals
Python Testing FundamentalsPython Testing Fundamentals
Python Testing Fundamentalscbcunc
 
Unit testing.pptx [repaired]
Unit testing.pptx [repaired]Unit testing.pptx [repaired]
Unit testing.pptx [repaired]Mohammad Asmar
 
How to test models using php unit testing framework?
How to test models using php unit testing framework?How to test models using php unit testing framework?
How to test models using php unit testing framework?satejsahu
 
Test Driven Development in Python
Test Driven Development in PythonTest Driven Development in Python
Test Driven Development in PythonAnoop Thomas Mathew
 
Unit testing presentation
Unit testing presentationUnit testing presentation
Unit testing presentationArthur Freyman
 

What's hot (19)

Unit testing Ch. 13 of Programming Ruby
Unit testing Ch. 13 of Programming RubyUnit testing Ch. 13 of Programming Ruby
Unit testing Ch. 13 of Programming Ruby
 
Learning php 7
Learning php 7Learning php 7
Learning php 7
 
unittest in 5 minutes
unittest in 5 minutesunittest in 5 minutes
unittest in 5 minutes
 
Automated testing in Drupal
Automated testing in DrupalAutomated testing in Drupal
Automated testing in Drupal
 
Debugging NET Applications With WinDBG
Debugging  NET Applications With WinDBGDebugging  NET Applications With WinDBG
Debugging NET Applications With WinDBG
 
Manage Selenium Grid with Terraform by Omkar Khatavkar (https://www.linkedin....
Manage Selenium Grid with Terraform by Omkar Khatavkar (https://www.linkedin....Manage Selenium Grid with Terraform by Omkar Khatavkar (https://www.linkedin....
Manage Selenium Grid with Terraform by Omkar Khatavkar (https://www.linkedin....
 
Code Igniter Code Sniffer
Code Igniter  Code SnifferCode Igniter  Code Sniffer
Code Igniter Code Sniffer
 
20140408 tdd puppetcamp-paris
20140408 tdd puppetcamp-paris20140408 tdd puppetcamp-paris
20140408 tdd puppetcamp-paris
 
Odoo profiler
Odoo profilerOdoo profiler
Odoo profiler
 
Successful Joomla migrations that don't hurt Search Engine Rankings
Successful Joomla migrations that don't hurt Search Engine RankingsSuccessful Joomla migrations that don't hurt Search Engine Rankings
Successful Joomla migrations that don't hurt Search Engine Rankings
 
Cucumber
CucumberCucumber
Cucumber
 
Specs2 3.4
Specs2 3.4Specs2 3.4
Specs2 3.4
 
Test Driven In Groovy
Test Driven In GroovyTest Driven In Groovy
Test Driven In Groovy
 
Template Method Design Pattern
Template Method Design PatternTemplate Method Design Pattern
Template Method Design Pattern
 
Python Testing Fundamentals
Python Testing FundamentalsPython Testing Fundamentals
Python Testing Fundamentals
 
Unit testing.pptx [repaired]
Unit testing.pptx [repaired]Unit testing.pptx [repaired]
Unit testing.pptx [repaired]
 
How to test models using php unit testing framework?
How to test models using php unit testing framework?How to test models using php unit testing framework?
How to test models using php unit testing framework?
 
Test Driven Development in Python
Test Driven Development in PythonTest Driven Development in Python
Test Driven Development in Python
 
Unit testing presentation
Unit testing presentationUnit testing presentation
Unit testing presentation
 

Similar to JUnit 4 Can it still teach us something? - Andrzej Jóźwiak - Kariera IT Łodź 2019

Puppet Camp Paris 2014: Test Driven Development
Puppet Camp Paris 2014: Test Driven DevelopmentPuppet Camp Paris 2014: Test Driven Development
Puppet Camp Paris 2014: Test Driven DevelopmentPuppet
 
TDD with Puppet Tutorial presented at Cascadia IT Conference 2014-03-07
TDD with Puppet Tutorial presented at Cascadia IT Conference 2014-03-07TDD with Puppet Tutorial presented at Cascadia IT Conference 2014-03-07
TDD with Puppet Tutorial presented at Cascadia IT Conference 2014-03-07garrett honeycutt
 
Oh so you test? - A guide to testing on Android from Unit to Mutation
Oh so you test? - A guide to testing on Android from Unit to MutationOh so you test? - A guide to testing on Android from Unit to Mutation
Oh so you test? - A guide to testing on Android from Unit to MutationPaul Blundell
 
Strategies for Puppet code upgrade and refactoring
Strategies for Puppet code upgrade and refactoringStrategies for Puppet code upgrade and refactoring
Strategies for Puppet code upgrade and refactoringAlessandro Franceschi
 
A la découverte des google/mock (aka gmock)
A la découverte des google/mock (aka gmock)A la découverte des google/mock (aka gmock)
A la découverte des google/mock (aka gmock)Thierry Gayet
 
New Ideas for Old Code - Greach
New Ideas for Old Code - GreachNew Ideas for Old Code - Greach
New Ideas for Old Code - GreachHamletDRC
 
utPLSQL: Unit Testing for Oracle PL/SQL
utPLSQL: Unit Testing for Oracle PL/SQLutPLSQL: Unit Testing for Oracle PL/SQL
utPLSQL: Unit Testing for Oracle PL/SQLSteven Feuerstein
 
Java Performance, Threading and Concurrent Data Structures
Java Performance, Threading and Concurrent Data StructuresJava Performance, Threading and Concurrent Data Structures
Java Performance, Threading and Concurrent Data StructuresHitendra Kumar
 
Mockito with a hint of PowerMock
Mockito with a hint of PowerMockMockito with a hint of PowerMock
Mockito with a hint of PowerMockYing Zhang
 
OverviewAssignment 1 Hypothetical Machine SimulatorCSci 43.docx
OverviewAssignment 1  Hypothetical Machine SimulatorCSci 43.docxOverviewAssignment 1  Hypothetical Machine SimulatorCSci 43.docx
OverviewAssignment 1 Hypothetical Machine SimulatorCSci 43.docxhoney690131
 
20140406 loa days-tdd-with_puppet_tutorial
20140406 loa days-tdd-with_puppet_tutorial20140406 loa days-tdd-with_puppet_tutorial
20140406 loa days-tdd-with_puppet_tutorialgarrett honeycutt
 
Property based tests and where to find them - Andrzej Jóźwiak - TomTom Webina...
Property based tests and where to find them - Andrzej Jóźwiak - TomTom Webina...Property based tests and where to find them - Andrzej Jóźwiak - TomTom Webina...
Property based tests and where to find them - Andrzej Jóźwiak - TomTom Webina...Andrzej Jóźwiak
 
Java - A broad introduction
Java - A broad introductionJava - A broad introduction
Java - A broad introductionBirol Efe
 
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018Mike Harris
 
Unit Testing Android Applications
Unit Testing Android ApplicationsUnit Testing Android Applications
Unit Testing Android ApplicationsRody Middelkoop
 

Similar to JUnit 4 Can it still teach us something? - Andrzej Jóźwiak - Kariera IT Łodź 2019 (20)

Puppet Camp Paris 2014: Test Driven Development
Puppet Camp Paris 2014: Test Driven DevelopmentPuppet Camp Paris 2014: Test Driven Development
Puppet Camp Paris 2014: Test Driven Development
 
TDD with Puppet Tutorial presented at Cascadia IT Conference 2014-03-07
TDD with Puppet Tutorial presented at Cascadia IT Conference 2014-03-07TDD with Puppet Tutorial presented at Cascadia IT Conference 2014-03-07
TDD with Puppet Tutorial presented at Cascadia IT Conference 2014-03-07
 
Greach 2015 Spock workshop
Greach 2015 Spock workshopGreach 2015 Spock workshop
Greach 2015 Spock workshop
 
Spring IO 2015 Spock Workshop
Spring IO 2015 Spock WorkshopSpring IO 2015 Spock Workshop
Spring IO 2015 Spock Workshop
 
Ansible testing
Ansible   testingAnsible   testing
Ansible testing
 
Oh so you test? - A guide to testing on Android from Unit to Mutation
Oh so you test? - A guide to testing on Android from Unit to MutationOh so you test? - A guide to testing on Android from Unit to Mutation
Oh so you test? - A guide to testing on Android from Unit to Mutation
 
Strategies for Puppet code upgrade and refactoring
Strategies for Puppet code upgrade and refactoringStrategies for Puppet code upgrade and refactoring
Strategies for Puppet code upgrade and refactoring
 
A la découverte des google/mock (aka gmock)
A la découverte des google/mock (aka gmock)A la découverte des google/mock (aka gmock)
A la découverte des google/mock (aka gmock)
 
New Ideas for Old Code - Greach
New Ideas for Old Code - GreachNew Ideas for Old Code - Greach
New Ideas for Old Code - Greach
 
Java 9 Features
Java 9 FeaturesJava 9 Features
Java 9 Features
 
utPLSQL: Unit Testing for Oracle PL/SQL
utPLSQL: Unit Testing for Oracle PL/SQLutPLSQL: Unit Testing for Oracle PL/SQL
utPLSQL: Unit Testing for Oracle PL/SQL
 
Java Performance, Threading and Concurrent Data Structures
Java Performance, Threading and Concurrent Data StructuresJava Performance, Threading and Concurrent Data Structures
Java Performance, Threading and Concurrent Data Structures
 
Mockito with a hint of PowerMock
Mockito with a hint of PowerMockMockito with a hint of PowerMock
Mockito with a hint of PowerMock
 
OverviewAssignment 1 Hypothetical Machine SimulatorCSci 43.docx
OverviewAssignment 1  Hypothetical Machine SimulatorCSci 43.docxOverviewAssignment 1  Hypothetical Machine SimulatorCSci 43.docx
OverviewAssignment 1 Hypothetical Machine SimulatorCSci 43.docx
 
20140406 loa days-tdd-with_puppet_tutorial
20140406 loa days-tdd-with_puppet_tutorial20140406 loa days-tdd-with_puppet_tutorial
20140406 loa days-tdd-with_puppet_tutorial
 
Property based tests and where to find them - Andrzej Jóźwiak - TomTom Webina...
Property based tests and where to find them - Andrzej Jóźwiak - TomTom Webina...Property based tests and where to find them - Andrzej Jóźwiak - TomTom Webina...
Property based tests and where to find them - Andrzej Jóźwiak - TomTom Webina...
 
Java - A broad introduction
Java - A broad introductionJava - A broad introduction
Java - A broad introduction
 
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
How I Learned to Stop Worrying and Love Legacy Code - Ox:Agile 2018
 
Unit Testing Android Applications
Unit Testing Android ApplicationsUnit Testing Android Applications
Unit Testing Android Applications
 
Testing Ansible
Testing AnsibleTesting Ansible
Testing Ansible
 

More from Andrzej Jóźwiak

Encapsulation – the pitfalls of Object-Oriented Programming - Andrzej Jóźwiak...
Encapsulation – the pitfalls of Object-Oriented Programming - Andrzej Jóźwiak...Encapsulation – the pitfalls of Object-Oriented Programming - Andrzej Jóźwiak...
Encapsulation – the pitfalls of Object-Oriented Programming - Andrzej Jóźwiak...Andrzej Jóźwiak
 
Does testability imply good design - Andrzej Jóźwiak - TomTom Dev Day 2022
Does testability imply good design - Andrzej Jóźwiak - TomTom Dev Day 2022Does testability imply good design - Andrzej Jóźwiak - TomTom Dev Day 2022
Does testability imply good design - Andrzej Jóźwiak - TomTom Dev Day 2022Andrzej Jóźwiak
 
Introduction to the Kotlin programming language - Andrzej Jóźwiak - JUG Łódź ...
Introduction to the Kotlin programming language - Andrzej Jóźwiak - JUG Łódź ...Introduction to the Kotlin programming language - Andrzej Jóźwiak - JUG Łódź ...
Introduction to the Kotlin programming language - Andrzej Jóźwiak - JUG Łódź ...Andrzej Jóźwiak
 
Capability Driven Design - Andrzej Jóźwiak - TomTom Dev Day 2021
Capability Driven Design - Andrzej Jóźwiak  - TomTom Dev Day 2021Capability Driven Design - Andrzej Jóźwiak  - TomTom Dev Day 2021
Capability Driven Design - Andrzej Jóźwiak - TomTom Dev Day 2021Andrzej Jóźwiak
 
Types of Randomness in Game Design - Rapid Talks - December 2020
Types of Randomness in Game Design - Rapid Talks - December 2020Types of Randomness in Game Design - Rapid Talks - December 2020
Types of Randomness in Game Design - Rapid Talks - December 2020Andrzej Jóźwiak
 
Capability Driven Design - Rapid Talks - November 2020
Capability Driven Design - Rapid Talks - November 2020Capability Driven Design - Rapid Talks - November 2020
Capability Driven Design - Rapid Talks - November 2020Andrzej Jóźwiak
 
Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020
Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020
Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020Andrzej Jóźwiak
 

More from Andrzej Jóźwiak (7)

Encapsulation – the pitfalls of Object-Oriented Programming - Andrzej Jóźwiak...
Encapsulation – the pitfalls of Object-Oriented Programming - Andrzej Jóźwiak...Encapsulation – the pitfalls of Object-Oriented Programming - Andrzej Jóźwiak...
Encapsulation – the pitfalls of Object-Oriented Programming - Andrzej Jóźwiak...
 
Does testability imply good design - Andrzej Jóźwiak - TomTom Dev Day 2022
Does testability imply good design - Andrzej Jóźwiak - TomTom Dev Day 2022Does testability imply good design - Andrzej Jóźwiak - TomTom Dev Day 2022
Does testability imply good design - Andrzej Jóźwiak - TomTom Dev Day 2022
 
Introduction to the Kotlin programming language - Andrzej Jóźwiak - JUG Łódź ...
Introduction to the Kotlin programming language - Andrzej Jóźwiak - JUG Łódź ...Introduction to the Kotlin programming language - Andrzej Jóźwiak - JUG Łódź ...
Introduction to the Kotlin programming language - Andrzej Jóźwiak - JUG Łódź ...
 
Capability Driven Design - Andrzej Jóźwiak - TomTom Dev Day 2021
Capability Driven Design - Andrzej Jóźwiak  - TomTom Dev Day 2021Capability Driven Design - Andrzej Jóźwiak  - TomTom Dev Day 2021
Capability Driven Design - Andrzej Jóźwiak - TomTom Dev Day 2021
 
Types of Randomness in Game Design - Rapid Talks - December 2020
Types of Randomness in Game Design - Rapid Talks - December 2020Types of Randomness in Game Design - Rapid Talks - December 2020
Types of Randomness in Game Design - Rapid Talks - December 2020
 
Capability Driven Design - Rapid Talks - November 2020
Capability Driven Design - Rapid Talks - November 2020Capability Driven Design - Rapid Talks - November 2020
Capability Driven Design - Rapid Talks - November 2020
 
Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020
Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020
Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020
 

Recently uploaded

Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxnada99848
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 

Recently uploaded (20)

Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptx
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 

JUnit 4 Can it still teach us something? - Andrzej Jóźwiak - Kariera IT Łodź 2019

  • 1. can it still teach us something? Andrzej Jóźwiak andrzej.jozwiak@gmail.com ajoz.github.io https://github.com/artificialrevelations 4
  • 3. use kariera-it-20 discount code to get 20% off
  • 4.
  • 5.
  • 6.
  • 7.
  • 8. Empty Non-Empty push pop push new getDepth = 0 isEmpty = true p e e k p o p Exception getDepth = N* isEmpty = false An immutable Stack, with two distinct states
  • 9.
  • 10.
  • 11.
  • 12.
  • 13. “So who should you be writing the tests for? For the person trying to understand your code. Good tests act as documentation for the code they are testing. They describe how the code works.” Gerard Meszaros 97 Things Every Programmer Should Know by Kevlin Henney
  • 14. Given: there is no stack When: a stack is created Then: it is empty
  • 15. Given: there is no stack When: a stack is created Then: it is has a depth of zero
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22. Enclosed Runner - Gives us only one level of nesting :-( - Enclosed is a suite thus each inner static class can be run with a different runner :-) - Abstract inner classes are ignored thus adding an abstract keyword can disable a test - Shared setup (all the @Before and @After) needs to be hidden inside an abstract class (which won’t be run) - JUnit5 has a @Nested annotation that allows for deeper nesting then a single level
  • 23.
  • 24.
  • 25. ExpectedException Rule - no explicit try/catch block - it’s possible to expect an exception just before the point it will happen, this avoids the situation where something else throws a similar exception - it’s possible to match part of the exception message - deprecated in 4.13 :-( - does not exist in JUnit 5.x :-( - usage of Assert.assertThrows is encouraged
  • 26.
  • 27. TemporaryFolder Rule - allows creating a temporary directory structure, create files, directories etc - can recursively create directories - Starting with version 4.13 allows strict verification of deleted resources which fails the test with AssertionError if resources cannot be deleted - only in compatibility mode in JUnit 5 :-(
  • 28.
  • 29. ExternalResource Rule - Great example of such ExternalResource is MockWebServer from okhttp - Very useful for working with any kind of in memory database - Can help setup any form of dependency injection - For sending information to some external service before and after the test - sky is the limit ;-)
  • 30.
  • 31. RuleChain - the ordering might be important for example if we have a rule that starts the app and closes it at the end, so if we want to do some screenshots of the running app we need to run the screenshot rule before the app closing rule will finish - when ordering is the key - when rules depend on each other
  • 32.
  • 33. What we want? - create a test that checks the depth after some amount of operations performed on the stack - specify the amount of push operations - specify the amount of pop operations - specify the expected depth of the stack
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39. Parametrized - ugly syntax :-( (JUnitParams library does this better) - we can run @Before and @After like in a normal test - we can have more than one test method but we need assumptions to control the values that are fed to our test - can easily grow in size - we need to think about all the examples beforehand
  • 40. Can we test general properties of our code without giving specific examples?
  • 41.
  • 42.
  • 43.
  • 45. Theories - not supported in JUnit5 but property based testing as a concept can be done through other libraries e.g. jqwik - can have fixed data points - can have multiple different sources of generated values - should probably be under smoke test category - are not easy to define properly
  • 46. Good Properties - business rules as a property - using the same input will produce the same output - applying functions that are inverse should result with the initial state - doing something multiple times won’t change the result - some operations should not change other existing properties of the tested code/structure/class e.g. sorting won’t change the size, filtering won’t change the order - sometimes order of operations won’t change the result e.g. fiter(sort) == sort(filter)