From: Mike Jackson Date: Tue, 16 Apr 2013 15:49:46 +0000 (-0700) Subject: Reordered introduction of expected-run-compare description and nose introduction X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=c9c08776a5aa202a9107db4d5108536cf5b767fa;p=swc-testing-nose.git Reordered introduction of expected-run-compare description and nose introduction --- diff --git a/testing/Writing.md b/testing/Writing.md index 7d9cd2f..7b58488 100755 --- a/testing/Writing.md +++ b/testing/Writing.md @@ -100,12 +100,6 @@ Then we can add all our test functions and function calls to this file. And run $ python test_dna.py -## `nose` - a Python test framework - -`nose` is a test framework for Python that will automatically find, run and report on tests written in Python. It is an example of what has been termed an *[xUnit test framework](http://en.wikipedia.org/wiki/XUnit)*, perhaps the most famous being JUnit for Java. - -To use `nose`, we write test functions, as we've been doing, with the prefix `test_` and put these in files, likewise prefixed by `test_`. The prefixes `Test-`, `Test_` and `test-` can also be used. - Typically, a test function, * Sets up some inputs and the associated expected outputs. The expected outputs might be a single number, a range of numbers, some text, a file, a set of files, or whatever. @@ -124,18 +118,11 @@ Python `assert` allows us to check, assert should_be_true() assert not should_not_be_true() -`nose` defines additional functions which can be used to check for a rich range of conditions e.g.. - - from nose.tools import * +## `nose` - a Python test framework - assert_equal(a, b) - assert_almost_equal(a, b, 3) - assert_true(a) - assert_false(a) - assert_raises(exception, func, *args, **kwargs) - ... +`nose` is a test framework for Python that will automatically find, run and report on tests written in Python. It is an example of what has been termed an *[xUnit test framework](http://en.wikipedia.org/wiki/XUnit)*, perhaps the most famous being JUnit for Java. -`assert_raises` is used for where we want to test that an exception is raised if, for example, we give a function a bad input. +To use `nose`, we write test functions, as we've been doing, with the prefix `test_` and put these in files, likewise prefixed by `test_`. The prefixes `Test-`, `Test_` and `test-` can also be used. To run `nose` for our tests, we can do, @@ -152,6 +139,19 @@ nosetests can output an "xUnit" test report, This is a standard format that that is supported by a number of xUnit frameworks which can then be converted to HTML and presented online. +`nose` defines additional functions which can be used to check for a rich range of conditions e.g.. + + from nose.tools import * + + assert_equal(a, b) + assert_almost_equal(a, b, 3) + assert_true(a) + assert_false(a) + assert_raises(exception, func, *args, **kwargs) + ... + +`assert_raises` is used for where we want to test that an exception is raised if, for example, we give a function a bad input. + ## Write some more tests Let's spend a few minutes coming up with some more tests for `calculate_weight`. Consider,