9
Minitest Raphael Monteiro Bankfacil 18/02/2015

Minitest

Embed Size (px)

Citation preview

Page 1: Minitest

MinitestRaphael Monteiro

Bankfacil

18/02/2015

Page 2: Minitest

Summary

● What is Minitest?● Minitest vs Rspec● Main assertions (syntax)● Reasons to use Minitest● Minitest into Rails● Minitest into Bankfacil● Further...

Page 3: Minitest

What is Minitest?

Minitest provides a complete suite of testing facilities.● minitest/unit● minitest/spec● minitest/benchmark● minitest/mock● minitest/pride

Page 4: Minitest

Minitest vs Rspec● "rspec is a testing DSL. minitest is ruby." - Adam

Hawkins, "Bow Before Minitest"● "Rspec is not about testing - it's about

documentation. That's why I prefer it" - Rahoul Baruah

Page 5: Minitest

Main assertions (syntax)● stub e mock

test 'execute' do

mock = Minitest::Mock.new

LeadToBkfApplicationCreator.stub(:new, mock,

lead_icarros) do

mock.expect(:create, true)

@ruler.execute(lead_icarros)

end

assert mock.verify

end

● more ex:

Page 6: Minitest

Reasons to use minitest

● Faster and lighter than Rspec● It is Ruby, no magic● Random & parallel tests● It is part of Ruby and Rails

Page 7: Minitest

Minitest into Rails● Since version 1.9, Ruby provides Minitest● test folder● setup and teardown methods● fixtures

# lo & behold! I am a YAML comment!david: name: David Heinemeier Hansson birthday: 1979-10-15 profession: Systems development

● rake test

Page 8: Minitest

Minitest into Bankfacil

● auto_financing project● assertions not spec● minitest-focus● minitest-reporters

class MyTest < MiniTest::Unit::TestCase

def test_unrelated; ...; end

focus

def test_method; ...; end # only

this one will run

def test_method_edgecase; ...; end

end

Page 9: Minitest

Further...● Official website: https://github.com/seattlerb/minitest● Ruby on Rails guides: http://guides.rubyonrails.org/v3.2.13/testing.html● Bow Before Minitest by Adam Hawkins: https://speakerdeck.

com/ahawkins/bow-before-minitest● RubyInside: http://www.rubyinside.com/dhh-offended-by-rspec-debate-4610.

html● Minitest Quick Reference: http://www.mattsears.

com/articles/2011/12/10/minitest-quick-reference● 7 Reasons I’m sticking with minitest: http://brandonhilkert.com/blog/7-reasons-

why-im-sticking-with-minitest-and-fixtures-in-rails/● 7 Reasons I love minitest: https://blog.engineyard.com/2014/seven-reasons-i-

love-minitest