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

%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 

Recently uploaded (20)

%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
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
%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
 
%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
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 

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