[openstack-dev] When is it okay for submitters to say 'I don't want to add tests' ?

Khanh-Toan Tran khanh-toan.tran at cloudwatt.com
Fri Nov 1 22:52:36 UTC 2013


Hey thanks a lot!

----- Original Message -----
From: "Clint Byrum" <clint at fewbar.com>
To: "openstack-dev" <openstack-dev at lists.openstack.org>
Sent: Thursday, October 31, 2013 7:49:55 PM
Subject: Re: [openstack-dev] When is it okay for submitters to say 'I don't	want to add tests' ?

Excerpts from Khanh-Toan Tran's message of 2013-10-31 07:22:06 -0700:
> Hi all,
> 
> As a newbie of the community, I'm not familiar with unittest and how to use it here. I've learned that Jenkins runs tests
> everytime we submit some code. But how to write the test and what is a 'good test' and a 'bad test'? I saw some commits
> in gerrit but am unable to say if the written test is enough to judge the code, since it is the author of the code who writes
> the test. Is there a framework to follow or some rules/pratices to respect?
> 
> Do you have some links to help me out?
> 

This is a nice synopsis of the concept of test driven development:

http://net.tutsplus.com/tutorials/python-tutorials/test-driven-development-in-python/

In OpenStack we always put tests in  _base_module_name_/tests, So if you
are working on nova, you can see the unit tests in:

nova/tests

You can generally always run the tests by installing the 'tox' python
module/command on your system and running 'tox' in the root of the git
repository.

Projects use various testing helpers to make tests easier to read and
write. The most common one is testtools. A typical test will look like
this:


import testtools

from basemodule import submodule


class TestSubmoduleFoo(testtools.TestCase):
    def test_foo_apple(self):
        self.assertEquals(1, submodule.foo('apple'))

    def test_foo_banana(self):
        self.assertEquals(0, submodule.foo('banana'))


Often unit tests will include mocks and fakes to hide real world
interfacing code from the unit tests. You would do well to read up on
how those concepts work as well, google for 'python test mocking' and
'python test fakes'.

Good luck, and #openstack-dev is always there to try and help. :)

_______________________________________________
OpenStack-dev mailing list
OpenStack-dev at lists.openstack.org
http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev



More information about the OpenStack-dev mailing list