SlideShare a Scribd company logo
1 of 29
Testing with Midje
Tobias Bayer
:clojureD 2015, Berlin
BBC, http://ichef.bbci.co.uk/naturelibrary/images/ic/credit/640x395/h/hi/highland_midge/highland_midge_1.jpg
Midge Midje
Tobias Bayer
inovex GmbH
tobias.bayer@inovex.de
codebrickie
Why Midje?
Non-lispy expectation syntax
(conj [1 2] 3) => [1 2 3]
vs
(is (= [1 2 3] (conj [1 2] 3)))
Why Midje?
Helpers and tools
Checking functions for expectations
Simple stubbing and mocking
Auto-testing
...
Facts
Checkables
Checkers
Prerequisites
Basic Building Blocks
Midje equivalent of a test
Facts
(facts "about +"
(fact "1 plus 2 equals 3"
(+ 1 2) => 3)
(fact
(+ -1 -1) => -2))
Facts
(future-fact "it returns fancy"
(fancy-function) => "fancy")
;; => WORK TO DO
Facts
(facts "about +"
(fact "1 plus 2 equals 3"
(+ 1 2) => 3))
Checkables
(facts "about +"
(fact "1 plus 2 equals 3"
(+ 1 2) => 3))
Checkables
(facts "about +"
(fact
(+ 1 1) =not=> 3))
Checkables
Can be used instead of values on the right side
of a checkable
Checkers
(facts "about my list"
(fact "it contains the value 5"
'(1 2 3 4 5 6) => (contains 5))
(fact "it contains the values 2 and 3"
'(1 2 3 4 5 6) => (contains 2 3))
(fact "it contains an odd number followed by
an even number"
'(1 2 3 4 5 6) => (contains odd? even?)))
Checkers - contains
(facts "about my map"
(fact "the value of x is 1"
{:x 1 :y 2} => (contains {:x 1}))
(fact "the value of y is even"
{:x 1 :y 2} => (contains {:y even?})))
Checkers - contains
(throwing-function) =>
(throws Exception)
(throwing-function) =>
(throws Exception "foo")
(throwing-function) =>
(throws Exception #"(foo|bar)")
Checkers - throws
(fact "insert-value has a side effect"
(reset-values) => irrelevant
(exists-value? "foo") => falsey
(insert-value "foo") => irrelevant
(exists-value? "foo") => truthy)
Checkers - anything/irrelevant
(defn each-element-is-one-of [expected-elements]
(fn [actual]
(every? (set expected-elements) actual)))
(fact "each element is one of 1-10"
'(1 2 3 4 5 6) => (each-element-is-one-of (range 1 11)))
Checkers - own checkers
OO-world: stubbing and mocking
Prerequisites
(defn find-user [username]
;; Code that finds the user in the database
)
(defn authenticate [username password]
(let [user (find-user username)]
(if (= (:password user) password)
user)))
(fact "it authenticates a user with a valid password"
(authenticate "the fly" "12345") => truthy
(provided
(find-user "the fly") =>
{:name "the fly" :password "12345"}))
Prerequisites - Stub
(fact "it calls the second function 5 times with argument
'foo'"
(first-function "foo") => irrelevant
(provided
(second-function "foo") => irrelevant :times 5))
(fact "it never calls the third function with any
argument"
(first-function "foo") => irrelevant
(provided
(third-function anything) => irrelevant :times 0))
Prerequisites - Mock
Project setup
~/.lein/profiles.clj
{:user {:plugins [[lein-midje "3.1.3"]]}}
Project setup
lein new midje midje-intro
Project setup
lein new midje midje-intro
Project setup
lein new midje midje-intro
DEMO

More Related Content

What's hot

Sorting programs
Sorting programsSorting programs
Sorting programs
Varun Garg
 
ECMAScript 6 major changes
ECMAScript 6 major changesECMAScript 6 major changes
ECMAScript 6 major changes
hayato
 

What's hot (20)

Sorting programs
Sorting programsSorting programs
Sorting programs
 
20180721 code defragment
20180721 code defragment20180721 code defragment
20180721 code defragment
 
ECMAScript 6 major changes
ECMAScript 6 major changesECMAScript 6 major changes
ECMAScript 6 major changes
 
The Ring programming language version 1.5.3 book - Part 70 of 184
The Ring programming language version 1.5.3 book - Part 70 of 184The Ring programming language version 1.5.3 book - Part 70 of 184
The Ring programming language version 1.5.3 book - Part 70 of 184
 
20181020 advanced higher-order function
20181020 advanced higher-order function20181020 advanced higher-order function
20181020 advanced higher-order function
 
Property-based testing
Property-based testingProperty-based testing
Property-based testing
 
ES6(ES2015) is beautiful
ES6(ES2015) is beautifulES6(ES2015) is beautiful
ES6(ES2015) is beautiful
 
20180310 functional programming
20180310 functional programming20180310 functional programming
20180310 functional programming
 
Tech Talk - Immutable Data Structure
Tech Talk - Immutable Data StructureTech Talk - Immutable Data Structure
Tech Talk - Immutable Data Structure
 
The evolution of redux action creators
The evolution of redux action creatorsThe evolution of redux action creators
The evolution of redux action creators
 
Clojure functions examples
Clojure functions examplesClojure functions examples
Clojure functions examples
 
99 líneas que lo simplifican todo( sin animar)
99 líneas que lo simplifican todo( sin animar)99 líneas que lo simplifican todo( sin animar)
99 líneas que lo simplifican todo( sin animar)
 
The Ring programming language version 1.5.2 book - Part 52 of 181
The Ring programming language version 1.5.2 book - Part 52 of 181The Ring programming language version 1.5.2 book - Part 52 of 181
The Ring programming language version 1.5.2 book - Part 52 of 181
 
Redux saga: managing your side effects. Also: generators in es6
Redux saga: managing your side effects. Also: generators in es6Redux saga: managing your side effects. Also: generators in es6
Redux saga: managing your side effects. Also: generators in es6
 
大量地区化解决方案V5
大量地区化解决方案V5大量地区化解决方案V5
大量地区化解决方案V5
 
Ocr code
Ocr codeOcr code
Ocr code
 
Redux Sagas - React Alicante
Redux Sagas - React AlicanteRedux Sagas - React Alicante
Redux Sagas - React Alicante
 
Introducción a Elixir
Introducción a ElixirIntroducción a Elixir
Introducción a Elixir
 
Sbaw090519
Sbaw090519Sbaw090519
Sbaw090519
 
Clock For My
Clock For MyClock For My
Clock For My
 

Similar to Testing with Midje

Front end fundamentals session 1: javascript core
Front end fundamentals session 1: javascript coreFront end fundamentals session 1: javascript core
Front end fundamentals session 1: javascript core
Web Zhao
 

Similar to Testing with Midje (20)

Mercado iOS & Swift vs Objective-C
Mercado iOS & Swift vs Objective-CMercado iOS & Swift vs Objective-C
Mercado iOS & Swift vs Objective-C
 
An introduction to property based testing
An introduction to property based testingAn introduction to property based testing
An introduction to property based testing
 
Functional Core, Reactive Shell
Functional Core, Reactive ShellFunctional Core, Reactive Shell
Functional Core, Reactive Shell
 
The lazy programmer's guide to writing thousands of tests
The lazy programmer's guide to writing thousands of testsThe lazy programmer's guide to writing thousands of tests
The lazy programmer's guide to writing thousands of tests
 
GoLightly: Building VM-Based Language Runtimes with Google Go
GoLightly: Building VM-Based Language Runtimes with Google GoGoLightly: Building VM-Based Language Runtimes with Google Go
GoLightly: Building VM-Based Language Runtimes with Google Go
 
Let the type system be your friend
Let the type system be your friendLet the type system be your friend
Let the type system be your friend
 
Scalapeno18 - Thinking Less with Scala
Scalapeno18 - Thinking Less with ScalaScalapeno18 - Thinking Less with Scala
Scalapeno18 - Thinking Less with Scala
 
Frege - consequently functional programming for the JVM
Frege - consequently functional programming for the JVMFrege - consequently functional programming for the JVM
Frege - consequently functional programming for the JVM
 
Unity 2018からのハイパフォーマンスな機能紹介
Unity 2018からのハイパフォーマンスな機能紹介Unity 2018からのハイパフォーマンスな機能紹介
Unity 2018からのハイパフォーマンスな機能紹介
 
Functional Programming Patterns (NDC London 2014)
Functional Programming Patterns (NDC London 2014)Functional Programming Patterns (NDC London 2014)
Functional Programming Patterns (NDC London 2014)
 
Excelマクロはじめの一歩
Excelマクロはじめの一歩Excelマクロはじめの一歩
Excelマクロはじめの一歩
 
Intro
IntroIntro
Intro
 
Python Puzzlers
Python PuzzlersPython Puzzlers
Python Puzzlers
 
TDC218SP | Trilha Kotlin - DSLs in a Kotlin Way
TDC218SP | Trilha Kotlin - DSLs in a Kotlin WayTDC218SP | Trilha Kotlin - DSLs in a Kotlin Way
TDC218SP | Trilha Kotlin - DSLs in a Kotlin Way
 
Indexing & query optimization
Indexing & query optimizationIndexing & query optimization
Indexing & query optimization
 
Monadologie
MonadologieMonadologie
Monadologie
 
GE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python ProgrammingGE8151 Problem Solving and Python Programming
GE8151 Problem Solving and Python Programming
 
Front end fundamentals session 1: javascript core
Front end fundamentals session 1: javascript coreFront end fundamentals session 1: javascript core
Front end fundamentals session 1: javascript core
 
ATS Programming
ATS ProgrammingATS Programming
ATS Programming
 
Something about Golang
Something about GolangSomething about Golang
Something about Golang
 

Recently uploaded

CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodology
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
 

Testing with Midje

Editor's Notes

  1. Has anyone ever been to the Scottish Highlands?
  2. Fortunately, you only have to replace one letter to improve things a lot. ;)
  3. My name is Tobias Bayer… I work as a developer for inovex inovex: medium sized Software Company from Karlsruhe with offices in Cologne and Munich (where I work) By the way, I’ll push the sample code I’ll be showing here to GitHub after the talk...
  4. These are some of the Midje examples I’ll walk you through in the talk… You can see some of the major building blocks of a Midje test… Name some of the building blocks: “facts” “=> arrow” “provided” live demo afterwards
  5. But, first things first. Why should you use Midje for testing Clojure apps? Or why do I prefer to use Midje?
  6. “non-lispy” at a Clojure conference more readable in tests, first execution _then_ expectation, grew up reading from left to right i also think it was done by mistake in JUnit when they put the expectation before the execution in the assert-methods :)
  7. A checkable is the heart of a fact Here you execute your function under test with its arguments and define your expectation
  8. Consists of three parts: left hand side, right hand side and arrow Function under test, arrow, expectation
  9. =not=> arrow Other arrows available
  10. ca. at 10 minutes
  11. anything/irrelevant -> prerequisites, side effects truthy/falsey -> nil/false not nil/true