Skip to content

breakreturn/tdd-lecture-examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

(c) 2015 Joakim Gross, joakimgross@gmail.com
Licensed under http://creativecommons.org/licenses/by-sa/4.0/
Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)

TDD/Unit test Examples

This repository contains code examples and instructions used in a TDD guest lecture and is intended to be used by attendees for reference and experimentation with the concepts introduced.

This readme is formatted in a way intended to look nice when rendered as markdown.

Setup

Examples in this repo are tested on Ubuntu 15.04.

To start experimenting with the examples in this repo, the required dependencies needs to be installed and an environment set up. Below are steps for doing that using virtualenv to create an isloated environment for python (using virtualenv is not actually required but can be nice if one feels uncertain about how the libraries and tools will affect the environment):

    apt-get install python-pip
    pip install virtualenv

Set up a directory where a virtualenv will be created:

    virtualenv ~/tdd-env
    source ~/tdd-env/bin/activate

A virtualenv should now has been set up (to 'exit' from it, type deactivate in the same terminal session as it was created).

Install the required tools in the virtualenv:

    pip install pytest
    pip install pytest-mock

Run examples

To run the unit tests, go to the root of this repo and type:

    py.test -v

List of examples

Directory contains the following modules:

  • simple.py - Simple python module with two very basic classes.
  • test_simple.py - Contains unit tests for the simple module.
  • problematic.py - Python module with a slightly triky external dependency.
  • test_problematic.py - Contains unit tests for the problematic module.

Start with the simple.py module implementation and then check how it's tested with test_simple.py. This test shows very simplistic examples of a unit test, a test using a stub, and a test using a mock.

Check out problematic.py and its tests in test_problematic.py for an example of monkeypatching to handle dependencies, again very simplified.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages