GithubHelp home page GithubHelp logo

unit-testing-training's Introduction

unit-testing-training

This repo provides a Python module (functions.py) and a corresponding module (functions_test.py) containing unit tests for functions.py.

Setup

After cloning this repo:

git clone [email protected]:optimizely/unit-testing-training.git

cd unit-testing-training

... run the shell script to install dependencies and create a virtualenv (this will ask for your system password):

./setup.sh

Then enter your new virtualenv:

source .virtualenv/bin/activate

And finally run all the Python tests in this repo:

python -m unittest discover

Where To Start

Try breaking one of the tests and rerunning the tests. In functions.py, change:

def add_three_to_value(value):
  return value + 3

to

def add_three_to_value(value):
  return value + 4

Then once again run:

python -m unittest discover

And you should see something like:

======================================================================
FAIL: test_add_three_to_value__with_seven (test_my_functions.MyFunctionsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/username/repos/unit-testing-training/test_my_functions.py", line 15, in test_add_three_to_value__with_seven
    self.assertEqual(10, my_functions.add_three_to_value(7))
AssertionError: 10 != 11

======================================================================
FAIL: test_add_three_to_value__with_ten (test_my_functions.MyFunctionsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/username/repos/unit-testing-training/test_my_functions.py", line 18, in test_add_three_to_value__with_ten
    self.assertEqual(13, my_functions.add_three_to_value(10))
AssertionError: 13 != 14

----------------------------------------------------------------------
Ran 6 tests in 0.002s

FAILED (failures=2)

Hopefully that helps makes the setup a bit more concrete. Fiddle freely with the tests!

More Reading/Viewing

unit-testing-training's People

Contributors

jgaul avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.