Skip to content

QuickStart

michaeljoseph edited this page Apr 13, 2012 · 4 revisions

QuickStart

We'll start with a simple test case:

    from testify import *
    
    class AdditionTestCase(TestCase):
        @class_setup
        def init_the_variable(self):
            self.variable = 0

        @setup
        def increment_the_variable(self):
            self.variable += 1

        def test_the_variable(self):
            assert_equal(self.variable, 1)

        @teardown
        def decrement_the_variable(self):
            self.variable -= 1

        @class_teardown
        def get_rid_of_the_variable(self):
            self.variable = None

    if __name__ == "__main__":
        run()

And then we'll want to run it.

We have two options:

  • If you have included the __main__ check in your test case, then you can just run the script like you would with unittest
  • Use the testify test runner

If you're working on a larger projects with lots of test cases, you'll likely want to use the test runner. Assuming your file layout is something like:

myapp/
  README
  lib/
  tests/
    mytest.py

Then just run:

testify tests

Run testify --help for all the options, or see RunningTests for more info.

Clone this wiki locally