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
Testing with Midje
Testing with Midje
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

DOCX
Modificacion del programa
PDF
Bindings: the zen of montage
PDF
The Ring programming language version 1.6 book - Part 55 of 189
PPTX
The redux saga begins
PPTX
Using Redux-Saga for Handling Side Effects
PDF
関数プログラミングことはじめ revival
PDF
ゼロから始めるScala文法
PDF
Clojure functions midje
Modificacion del programa
Bindings: the zen of montage
The Ring programming language version 1.6 book - Part 55 of 189
The redux saga begins
Using Redux-Saga for Handling Side Effects
関数プログラミングことはじめ revival
ゼロから始めるScala文法
Clojure functions midje

What's hot (20)

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

Similar to Testing with Midje (14)

PDF
Spock: Test Well and Prosper
PDF
Testing outside of the Ruby World
PDF
QuickCheck - Software Testing
PDF
PPTX
Schema, validation and generative testing
PPT
Behaviour-Driven Development
PPT
PPTX
Unit testing
KEY
Uses & Abuses of Mocks & Stubs
PDF
Junit Recipes - Elementary tests (2/2)
PDF
Behaviour Driven Development and Thinking About Testing
 
PDF
Bdd and-testing
PDF
Keeping objects healthy with Object::Exercise.
PPTX
Mutation Testing - Ruby Edition
Spock: Test Well and Prosper
Testing outside of the Ruby World
QuickCheck - Software Testing
Schema, validation and generative testing
Behaviour-Driven Development
Unit testing
Uses & Abuses of Mocks & Stubs
Junit Recipes - Elementary tests (2/2)
Behaviour Driven Development and Thinking About Testing
 
Bdd and-testing
Keeping objects healthy with Object::Exercise.
Mutation Testing - Ruby Edition
Ad

Recently uploaded (20)

PDF
SOFTWARE ENGINEERING Software Engineering (3rd Edition) by K.K. Aggarwal & Yo...
PPTX
Foundations of Marketo Engage: Nurturing
PPTX
ROI from Efficient Content & Campaign Management in the Digital Media Industry
PPTX
Plex Media Server 1.28.2.6151 With Crac5 2022 Free .
PDF
Understanding the Need for Systemic Change in Open Source Through Intersectio...
PDF
Engineering Document Management System (EDMS)
PDF
Workplace Software and Skills - OpenStax
PDF
Sanket Mhaiskar Resume - Senior Software Engineer (Backend, AI)
PPTX
Human-Computer Interaction for Lecture 2
PPTX
Streamlining Project Management in the AV Industry with D-Tools for Zoho CRM ...
PPTX
Viber For Windows 25.7.1 Crack + Serial Keygen
PDF
Ragic Data Security Overview: Certifications, Compliance, and Network Safegua...
PPTX
Human-Computer Interaction for Lecture 1
PPTX
A Spider Diagram, also known as a Radial Diagram or Mind Map.
PDF
What Makes a Great Data Visualization Consulting Service.pdf
PDF
CapCut PRO for PC Crack New Download (Fully Activated 2025)
PPTX
Lecture 5 Software Requirement Engineering
PDF
Bright VPN Crack Free Download (Latest 2025)
PDF
PDF-XChange Editor Plus 10.7.0.398.0 Crack Free Download Latest 2025
PPT
3.Software Design for software engineering
SOFTWARE ENGINEERING Software Engineering (3rd Edition) by K.K. Aggarwal & Yo...
Foundations of Marketo Engage: Nurturing
ROI from Efficient Content & Campaign Management in the Digital Media Industry
Plex Media Server 1.28.2.6151 With Crac5 2022 Free .
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Engineering Document Management System (EDMS)
Workplace Software and Skills - OpenStax
Sanket Mhaiskar Resume - Senior Software Engineer (Backend, AI)
Human-Computer Interaction for Lecture 2
Streamlining Project Management in the AV Industry with D-Tools for Zoho CRM ...
Viber For Windows 25.7.1 Crack + Serial Keygen
Ragic Data Security Overview: Certifications, Compliance, and Network Safegua...
Human-Computer Interaction for Lecture 1
A Spider Diagram, also known as a Radial Diagram or Mind Map.
What Makes a Great Data Visualization Consulting Service.pdf
CapCut PRO for PC Crack New Download (Fully Activated 2025)
Lecture 5 Software Requirement Engineering
Bright VPN Crack Free Download (Latest 2025)
PDF-XChange Editor Plus 10.7.0.398.0 Crack Free Download Latest 2025
3.Software Design for software engineering

Testing with Midje

Editor's Notes

  • #3: Has anyone ever been to the Scottish Highlands?
  • #4: Fortunately, you only have to replace one letter to improve things a lot. ;)
  • #5: 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...
  • #6: 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
  • #7: But, first things first. Why should you use Midje for testing Clojure apps? Or why do I prefer to use Midje?
  • #8: “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 :)
  • #14: A checkable is the heart of a fact Here you execute your function under test with its arguments and define your expectation
  • #15: Consists of three parts: left hand side, right hand side and arrow Function under test, arrow, expectation
  • #16: =not=> arrow Other arrows available
  • #17: ca. at 10 minutes
  • #21: anything/irrelevant -> prerequisites, side effects truthy/falsey -> nil/false not nil/true