[TIP] Parametrize tests for unit or integration testing
mateusz at loskot.net
Tue Feb 4 12:02:17 PST 2014
On 4 February 2014 19:21, andrea crotti <andrea.crotti.0 at gmail.com> wrote:
> 2014-02-01 Mateusz Łoskot <mateusz at loskot.net>:
>> This is my first post here, so hello everyone.
>> I was searching through the list archives and I stumbled upon this post
>> in which Benji mentions about writing
>> "a parameterized test and apply the same test twice. Once in an
>> environment where the "real" thing is used and once where the "stub" is used"
>> AFAIU, the idea is to write test(s) once, then parametrize for use in both
>> modes, as unit tests or integration tests.
>> Could anyone explain or give example how to implement
>> such parametrization?
>> Perhaps Benji is still around and could explain the original technique?
>> I'm using Python 3.2 or 3.3 and I write my tests using
>> unittest and mock (or unittest.mock) modules.
>> So, I'm interested in using those to to achieve the parametrized
>> tests for unit/integration testing modes.
> I always split integrations and unit tests in different directories,
> so it's to spot what is what and I can run unit tests in a commit hook
> We also have often unit and integration tests for the same modules,
> but that's just two different files..
On reflection, I realised such physical distinction is practical in my
case as well.
In Unit Tests, I often assert on mock objects which are not present in
integration tests. Even if corresponding tests/cases in both kinds of tests
verify the same behaviour, they're realisation is often different.
However, I see potential for parametrised unit tests
as in the examples posted by Andres.
Mateusz Łoskot, http://mateusz.loskot.net
More information about the testing-in-python