Bsu on rails_testing

21

Click here to load reader

description

 

Transcript of Bsu on rails_testing

Page 1: Bsu on rails_testing

Testing in Ruby

Testing in Ruby

By Pavel Shutin. April 2013

Page 2: Bsu on rails_testing

Testing in Ruby

Pavel Shutin

• https://github.com/pluff • http://linkedin.com/pub/pavel-shutin/56/440/168 • http://www.facebook.com/pavel.shutin • [email protected]

By Pavel Shutin. April 2013

Page 3: Bsu on rails_testing

Testing in Ruby

Test Typeshttp://tiny.cc/0m0luw

•Functional•Security•Performance•Recovery•Regression

By Pavel Shutin. April 2013

Page 4: Bsu on rails_testing

Testing in Ruby

Manual Testinghttp://tiny.cc/tk1luwhttp://tiny.cc/9l1luw

•People are slow•People can fail•Manual testing applies to more-a-less finished system

By Pavel Shutin. April 2013

Page 5: Bsu on rails_testing

Testing in Ruby

Automated Testing

•Fast!•Doesn't have human mistake factor•Allows to test at any point in time. •Gives an ability to quickly verify that you didn't broke anything!

By Pavel Shutin. April 2013

Page 6: Bsu on rails_testing

Testing in Ruby

Too good to be true!

•Complex usecases require a lot of time to represent in code.

•Frequently changing pieces of code require too much effort to maintain all tests.

By Pavel Shutin. April 2013

Page 7: Bsu on rails_testing

Testing in Ruby

Take best of both worlds

•Use automation for all critical\important parts of application

•Use automation everywhere where its reasonable

•Let your real users to test the rest

By Pavel Shutin. April 2013

Page 8: Bsu on rails_testing

Testing in Ruby

Why should developers write tests?

•Make sure you did the right thing!•Enforce yourself to do things right!•Make sure nobody will break it!•Catch any errors as soon as possible.

By Pavel Shutin. April 2013

Page 9: Bsu on rails_testing

Testing in Ruby

Testing tools in Ruby

• Minitest • Rspec • Cucumber • Capybara • FactoryGirl

By Pavel Shutin. April 2013

Page 10: Bsu on rails_testing

Testing in Ruby

Test structure

By Pavel Shutin. April 2013

Page 11: Bsu on rails_testing

Testing in Ruby

Test hooks & Lazy variables

By Pavel Shutin. April 2013

Page 12: Bsu on rails_testing

Testing in Ruby

TDD

Write tests as requirements to future code.Ensure tests are failingWrite code until tests are greenReview the code for refactoringDon't write a single line of code anymore!

By Pavel Shutin. April 2013

Page 13: Bsu on rails_testing

Testing in Ruby

By Pavel Shutin. April 2013

Page 14: Bsu on rails_testing

Testing in Ruby

Stubshttp://tiny.cc/0v1tuw

By Pavel Shutin. April 2013

Page 15: Bsu on rails_testing

Testing in Ruby

Mockshttp://tiny.cc/zs1tuw

By Pavel Shutin. April 2013

Page 16: Bsu on rails_testing

Testing in Ruby

To stub or not to stub?•Implementation matters? You can use stubs!

•Don't test the code you didn't write. Mock it!

•You can test libraries too to ensure valid interface.

•Really heavy method? Stub it.

By Pavel Shutin. April 2013

Page 17: Bsu on rails_testing

Testing in Ruby

Cucumber and BDDhttp://tiny.cc/hq1tuw

Given that a customer buys a blue garmentAnd I have two blue garments in stockAnd three black garments in stock.When he returns the garment for a replacement in black,Then I should have three blue garments in stockAnd two black garments in stock

By Pavel Shutin. April 2013

Page 18: Bsu on rails_testing

Testing in Ruby

F.I.R.S.T.http://tiny.cc/e81tuw

•Fast (10 tests per second at least)•Isolated (no reverse engineering)•Repeatable (no randoms, no traces)•Self-validated (passed/failed only)•Timely (tests before code)

By Pavel Shutin. April 2013

Page 19: Bsu on rails_testing

Testing in Ruby

Rubyist Library1. The Ruby Programming Language

2. Metaprogramming Ruby: Program Like the Ruby Pros

3. The Pragmatic Programmer: From Journeyman to Master

4. The Mythical Man-Month: Essays on Software Engineering

5. Code Complete: A Practical Handbook of Software Construction

By Pavel Shutin. April 2013

Page 20: Bsu on rails_testing

Testing in Ruby

Questions?

By Pavel Shutin. April 2013

Page 21: Bsu on rails_testing

Testing in Ruby

Thank you and Happy Testing

By Pavel Shutin. April 2013