Community

Zenoss Newsletter
Monitored by Zenoss
SourceForge.net Logo

Writing Zenoss Unit Tests

by zenoss last modified 2007-06-08 09:36

Unit tests are an increasingly important aspect of software development in a world where software gets more sophisticated and standards higher; this how to will show how to maintain and improve the quality of your code in Zenoss

Introduction

Standard unittest Tests

Support for doctest Tests

Testing.ZopeTestCase Tests

Integrating with zopectl test

Zenoss' Test Runner

Zenoss has a Zope product, ZenTestRunner, whose sole purpose it to run a specific group of tests. We did this in order to avoid running all the tests in the Products directory, such as with this command:

zopectl test --libdir /usr/local/zenoss/Products

Likewise, to run the collections of tests that are important to use, we didn't want to have to do the following:

zopectl test --libdir /usr/local/zenoss/Products/ZenModel
zopectl test --libdir /usr/local/zenoss/Products/ZenRelations
zopectl test --libdir /usr/local/zenoss/Products/Zen...

Now, all we have to do is run this:

zopectl test --libdir /usr/local/zenoss/Products/ZenTestRunner

All that is required by developers is that they add product tests to the test runner. This is done in the following manner:

  • Make sure your tests run by themselves:
    zopectl test --libdir /usr/local/zenoss/Products/ZenNewProduct
  • Go to the tests directory:
    cd /usr/local/zenoss/Products/ZenTestRunner/tests
  • Copy one of the existing tests to a name reflecting the product for which you are adding tests:
    cp testZenModel.py testZenNewProduct.py
  • Change the import line in the new file to reflect the new product name:
        from Products import ZenNewProduct as product
  • Save and quit, then run the suites to make sure everything is passing:
    zopectl test --libdir /usr/local/zenoss/Products/ZenTestRunner

Integrating with buildbot

AddThis Social Bookmark Button
Document Actions