A brief introduction
"I get paid for code that works, not for tests, so my philosophy is to test as little as possible to reach a given level of confidence …"
Kent Beck
No silver bullets
What is testing about?
Getting feedback,
as much frequent as we can
the sooner, the better
Taxonomy
Small
Medium
Large
Test by Scope
Unit Tests
Dependency Injection
Dependency Injection
VS
Test doubles
Test doubles (Fake)
Fake implenmentation just to make test pass
Test doubles (Stub)
Stubs provide canned answers to calls made during the test, usually not responding at all to anything outside what’s programmed in for the test.
Ruby (rspec)
Javascript (sinon)
Test doubles (Spy)
Spies are objects that also record some information based on how they were called
Test doubles (Mock)
Informal: think in a Stub which is also a Spy.
It also responds with default values to non-explicitly declared methods
PHP (phpunit)
Ruby (rspec-mock)
Javascript (sinon)
Integration test which want to be a unit test
FIRST(it)
Integration test which works with external system
Integration test which uses the UI
System Test
Who, when and where run the tests?
Automatic Testing
4 phases-tests
What we need?
Testing framewok families
XUnit
Java (Junit)
PHP (phpUnit)
RSpec (suite per class)
Node/Javascript (mocha/jasmine)
Ruby (rspec)
RSpec (suite per setup)
BDD (specification)
BDD (specification)
Ruby (cucumber)
Java (cucumber)
TIPS & TRICKS
Questions & Stupid Questions
¿Where I place my tests?
¿Where I place my tests?
Java Project (Test Class per Class)
MyProject/
src/
main/
java/
com.groupId.artifactId.MyClass.java
resources/
test/
java/
com.groupId.artifactId.MyClassTest.java
com.groupId.artifactId.it.suite.MyTestCaseIntegrationTest.java
resources/
Java Project (Class per SetUp)
MyProject/
src/
main/
…
test/
java/
com.groupId.artifactId.myclass.<SetUp1>Test.java
com.groupId.artifactId.myclass.<SetUp2>Test.java
…
¿Where I place my tests?
Android Project
MyProject/
AndroidManifest.xml
res/
... (resources for main application)
src/
... (source code for main application) ...
tests/
AndroidManifest.xml
res/
... (resources for tests)
src/
... (source code for tests)
NodeJs Project
MyProject/
lib/
myClass.js
main.js
test/
ut/
/suite
it/
lib/
myClassTest.js
IOS Project
MyIOSProject/
MyIOSProject/
... app code ...
MyIOSProjectTests/
... test code ...
¿Who tests the classes which test our classes?
Exactly, this is why it's so important our tests follow
¿Could you be able to rewrite the code only reading the tests definitions?
Tests, specially Black Box tests, should tell us an story
Well defined and complete scenarios for Acceptance Tests
I spend more time writing code to setup my SUT than writing tests. How do you solve it?
I duplicate too much code on objects creation, mocks definition and assertions
Important!!! Do it
Thanks!!!!!