Test-driven development

Test-driven development, or TDD, is just an iterative and incremental problem solving methodology

About this talk

  • High level TDD & BDD concepts
  • Why should we automate our tests?
  • Testing jargon
  • Testing frameworks
  • Live example

High level TDD & BDD concepts

Application lifecycle management

Plan: Decide what your software will do

Code: Write in how your software will do it

Build: Get a first feedback to ensure you haven't screwed up

Test: Ensure that your code does what was expected

Release: Put it into production

You are doing it wrong!

TDD cycle

TDD cycle

BDD + TDD cycle

Why should we automate our tests?

Reduce the feedback loop

Continuous delivery

Continuous delivery

vs Continuous deployment

Should I always do TDD?

Should I always do TDD?

Testing jargon

Unit test

The lowest level testing technique consisting of test cases for the smallest possible units of code. A single unit test usually checks only a particular small behavior, and a unit test case usually covers all functionality of a particular single function or class.

Acceptance test

High-level testing that consists in a process of verifying that a solution works for the user.

Refactoring

Refactoring is a controlled technique for improving the design of an existing code base.

Assertions

Assertions are statements that perform an actual check on the software's output.

Test Doubles

Test doubles are objects the test code creates and passes to the SUT (software under test) to replace real dependencies.

  • Dummies
  • Fakes
  • Stubs
  • Mocks

Fixtures

A particular environment that must be set up before a test can be run. It generally consists of setting up all test doubles and other dependencies for the software under test.

Test coverage

Any kind of metric that attempts to estimate the likelihood of important behavior of the SUT still not covered by tests.

Gherkin

A domain-specific language, business readable, that lets you describe your software behaviour without detailing how dat behaviour is implemented

  • Given
  • When
  • Then

Scenario: Gherkin example
Given one thing
  And another thing
  And yet another thing
When I open my eyes
Then I see something
  But I don't see something else

Testing frameworks

Mocha

Mocha is a feature-rich JavaScript test framework running on Node.js and the browser, making asynchronous testing simple and fun. Mocha tests run serially, allowing for flexible and accurate reporting, while mapping uncaught exceptions to the correct test cases. 

Chai

Chai is a BDD / TDD assertion library for node and the browser that can be delightfully paired with any javascript testing framework.

Istambul/ Isparta

Code coverage tools which provide coverage reports.

Sinon

Standalone test spies, stubs and mocks for JavaScript.
No dependencies, works with any unit testing framework.

Karma

A simple tool that allows you to execute JavaScript code in multiple real browsers.

Cucumber

A behaviour-driven development tool. Translates Gherkin syntax into automatic tests.


Scenario: Gherkin example
Given one thing
  And another thing
  And yet another thing
When I open my eyes
Then I see something
  But I don't see something else

Other frameworks

Live example

Resources

test-driven development

By Daniel de la Cruz Calvo

test-driven development

An introduction of concepts and tools for doing test driven development. A speech oriented to frontend developers.

  • 1,172