Loading presentation...

Present Remotely

Send the link below via email or IM

Copy

Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

DeleteCancel

Make your likes visible on Facebook?

Connect your Facebook account to Prezi and let your likes appear on your timeline.
You can change this under Settings & Account at any time.

No, thanks

A few words on Unit Testing

No description
by

Max Baryshnikov

on 19 December 2013

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of A few words on Unit Testing

A few words on Unit Testing
Classical Definition
A unit test is a piece of a code (usually a method) that invokes another piece of code and checks the correctness of some assumptions afterward.

If the assumptions turn out to be wrong, the unit test has failed.

A “unit” is a method or function.
The Meaning
We write code that tests another code
What is it?
Why do I need it?
How do I do it?
...spending 30% of your time fixing live issues?
...afraid of touching legacy code?
...not sure everything works after a simple change?
Are you...
Cost of Defects
$
, x1000
The symptoms
The Choice
Fix earlier == save money!
NO
YES
Writing tests take time, time == money
Example: reafctoring
with tests
Goods Units Tests
...should be automated and repeatable
...should be easy to implement
...once written should remain for future use
...anyone should be able to run 'em
...should run at a push of a button
...should run quickly
Integration Tests != Unit Tests
Unit Test tests "unit" in isolation; Integration test exercises many units together.
Drawbacks of Integration Tests
...should be easy to implement
...once written should remain for future use
...anyone should be able to run 'em
Traditional UT and TDD
write code
write test
run test
fix bugs
Write test that fails
Make it work
Eliminate redundancy
Isolation
Stubs
Mocks
Design
Continuous Integration
An external dependency is an object in your system that your code under
test interacts with, and over which you have no control. (Common
examples are filesystems, threads, memory, time, and so on.)
A stub is a controllable replacement for an existing dependency (or collaborator ) in the system. By using a stub, you can test your code without dealing with the dependency directly.
Interaction testing is testing how an object sends input to or receives input from other objects — how that object interacts with other objects.
A mock object is a fake object in the system that decides whether the unit test has passed or failed. It does so by verifying whether the object under test interacted as expected with the fake object. There’s usually no more than one mock per test.
Techniques we used to create testable code (such as interface extraction) actually influenced our application design
Testable code leads to state when your application designed in loosely coupled and highly cohesive way
Code coverage
"Code coverage is a measure used to describe the degree to which the source code of a program is tested by a particular test suite."
ikipedia:
How much code we want to cover?
Too little testing
Perfect amount of testing
Too much testing
Coverage = 60%-80%
Don't be too proud of this technological
terror you've created.

The ability to destroy a planet is insignificant
next to the power of unit testing.
Q&A
Full transcript