rethinking testing

43
Rethinking Testing towards your needs [email protected]

Upload: pdejuan

Post on 26-Jun-2015

519 views

Category:

Documents


0 download

DESCRIPTION

Nowadays, TDD, BDD, continuous testing and other methodologies have come into our attention when developing. Yet, we barely know what needs to be tested and why are we testing it? During the talk we will go through a bunch of testing methodologies.

TRANSCRIPT

Page 1: Rethinking Testing

Rethinking Testingtowards your needs

[email protected]

Page 2: Rethinking Testing
Page 3: Rethinking Testing
Page 4: Rethinking Testing

Testing

Test Driven Development

TestUnit

jUnit

eXtreme Programming

Rspec

Crash Test

Page 5: Rethinking Testing

“Our highest priority is to satisfythe customer through the earlyand continuous DELIVERY of VALUABLE software.”

The agile manifesto

Page 6: Rethinking Testing

WorkingCode

LowCost

OnTime

The Customer

Page 7: Rethinking Testing

The Needs of Customer

Working Code Acceptance Testing

Page 8: Rethinking Testing

Public Domain Wikimedia Commons

Page 9: Rethinking Testing

Design by Contract

• by B. Meyer

• Code enforces a contract

• Language provides constraints

– Before function call (Preconditions)

– After function call (Post Conditions)

– During all the function call (Invariants)

Page 10: Rethinking Testing

User.create! params[:user]

Pre conditions:

params[:user] is not empty.

Post conditions:

New instance returned is successful.

Raise exception w/errors otherwise.

Invariants:

params[:user] is not modifiable.

Database connection available.

Page 11: Rethinking Testing

Design by Contract

• Few implementations:

– Native in Eiffel

– As add-on like:

• Java “assert”

• .Net code contracts

• In Ruby

– A.Hunt created DBC.rb (~2000)

– Lost in translation

Page 12: Rethinking Testing

Code that verifies Code

• Focus on the valuable outputs

• Repeatable

• Regression

Page 13: Rethinking Testing

jUnit

• by Gamma & Beck since 1997

• by the time Java was “cool”

• Isolated Components

• TestCases & TestSuites

Page 14: Rethinking Testing

Test Driven Development (TDD)

• by Beck.

• Test First Design and then program.

• Small requirements.

• Verify functionality w/automated tests.

Page 15: Rethinking Testing

“the programmer should let

correctness proof

and program

grow hand in hand”

E.Dijsktra 1972

Page 16: Rethinking Testing

Failingtest

Passingtest

Refactor

The TDD Cycle

Page 17: Rethinking Testing

Failingtest

Passingtest

Fail toRefactor

No Refactor

Technical Debt Overdose

Page 18: Rethinking Testing

Failingtest

Passingtest

Refactor

Running Suite takes too long

Page 19: Rethinking Testing

“correctness concerns turn out to be a very effective

heuristic guidance”

E.Dijsktra 1972

Page 20: Rethinking Testing

Testing correctness - scales

Acceptance

Integration

Unit

As the user would do

The Ensamble.

The single component

Page 21: Rethinking Testing

By Jewgienij Bal, Wikimedia Commons

Page 22: Rethinking Testing

Plenty of Tools

Focus on Ruby

• Test-Unit

• RSpec

• Cucumber

Focus on Javascript

• QUnit

• Jasmine

• Gerbil

Page 23: Rethinking Testing

Plenty of Tools

Focus on Ruby

• Test-Unit

• RSpec• Cucumber

Focus on Javascript

• QUnit

• Jasmine

• Gerbil

Page 24: Rethinking Testing

RSpec

• Rails ready out-of-the-box

• Acceptance testing:

– Selenium driver

– Capybara

– spec/integration

Page 25: Rethinking Testing

What do we test?

• Rails app:

– Models

– Controllers

– Views

• Additionally:

– Services

– Components

Page 26: Rethinking Testing

Typical setup on Rails

Acceptance

Integration

Unit

Page 27: Rethinking Testing

.rspec

--colour

--format Fuubar

--profile

Additional gems:

Autotest

Specjour / Spork

Page 28: Rethinking Testing

Average runtime for test-suite for a small project (294 examples)

0

5

10

15

20

25

0 50 100 150 200 250 300 350

seco

nd

s

# example

Page 29: Rethinking Testing

y = 3E-05x2 - 0.0012x + 1.2525

y = 0.0033x2 - 1.6196x + 199.53

1

10

0 50 100 150 200 250 300 350

seco

nd

s

# example

Two different sets of tests

rspec profile

Selenium, APIs

Page 30: Rethinking Testing

Models && Persistence

• Object State & Transitions

• Custom methods and edge conditions

• Associations w/other objects

• Additional Validations

– Expected fields.

– Factories.

Page 31: Rethinking Testing

Controllers && Views

• Controllers:

– Don’t test them, do acceptance tests.

– Logic and state reside at Model level.

• Controllers that are APIs:

– Don´t test them, do integration tests.

• Views

– Do Acceptance testing for all actions available (not just CRUD).

Page 32: Rethinking Testing

Components

• Black Box Testing:

– Test parameters and results.

– Test correct invoking:

• Send Email: ActionMailer parameters.

• Draw a chart: HighChart parameters.

Page 33: Rethinking Testing

Services

• Test connectivity to services.

• Mocked for Integration Tests.

– Save responses in fixtures.

– Assume correct/wrong responses.

Page 34: Rethinking Testing

Javascript: Selenium driver

• Does a lot of things:

– Creates an instance of browser.

– Establishes connections.

– Executes requests, renders responses.

– Executes Javascript.

• Emulates the user experience– Browser “bugs”

Page 35: Rethinking Testing

Slow test suite

• Use a CI Server

– Postpone long tests.

• Avoid Rails boot time

– Decouple logic from Rails into POROs.

– Use a no_rails_spec_helper.

• Avoid API calls lag

– Mock external services.

Page 36: Rethinking Testing

Rspec

By Nicolas M. Perrault , Wikimedia Commons

Page 37: Rethinking Testing
Page 38: Rethinking Testing

Questions?

Page 39: Rethinking Testing

¡MUCHAS GRACIAS!

спасибi

Page 40: Rethinking Testing

References

• The Rspec Book, D. Chelimsky et al.

• TDD by Example, K. Beck

• Continuous Delivery, J.Humble

• The Pragmatic Programmer, A. Hunt

• The Humble Programmer, E. Dijkstra

http://www.cs.utexas.edu/~EWD/transcriptions/EWD03xx/EWD340.html

Page 41: Rethinking Testing

Is Cucumber a need?

• Rspec is good enough.

• “Simplicity –the art of maximizing the amount of work not done –

is essential.”

• Specs are easy to program than specs + steps.

• Customer Interaction vs tools.

Page 42: Rethinking Testing

Stress && Performace

• Staging environment.

• Monitor execution, APM:

– New Relic

– Air Brake

Page 43: Rethinking Testing

“…program testing can be a very effective way to show the presence of bugs, but [it] is hopelessly inadequate for showing their absence.”

E.Dijsktra 1972