[Python] pytest e classi

Manlio Perillo manlio.perillo a gmail.com
Mar 27 Ott 2015 14:30:21 CET


On Tue, Oct 27, 2015 at 1:47 PM, enrico franchi
<enrico.franchi a gmail.com> wrote:
>
> 2015-10-26 19:31 GMT+00:00 Manlio Perillo <manlio.perillo a gmail.com>:
>>
>> Per testare funzioni come somma di solito è preferibile usare una
>> tabella con l'input e l'output corretto; ad esempio:
>>
>> table = [ ((1, 2, 3), 5), ((3, 5, 7), 15), ...]
>>
>> def test_somma():
>>     for in, out in table:
>>         cc = CC(*in)
>>         assert cc.somma() == out
>>
>> CC(*in) è equivalente a CC(in[0], in[1], in[2]).
>
>
> Uhm... no. Questo e' un noto anti-pattern nel testing. Non si deve *mai*
> fare qualcosa del genere (a meno di non avere a che fare con un framework di
> test veramente primitivo).
>

> [...]

Bello, non lo conoscevo; grazie.
In effetti io uso solo unittest standard.

> http://xunitpatterns.com/Parameterized%20Test.html
>
> """
> Several early reviewers wrote to me about a variation they use regularly:
> the Tabular Test. The essence of this is the same as doing a Parameterized
> Test except that the entire table of values is in a single Test Method.
> Unfortunately, this makes the test an Eager Test (see Assertion Roulette on
> page X) because it verifies many test conditions. This isn't a problem when
> all the tests are passing but it does lead to a lack of Defect Localization
> (see Goals of Test Automation) when one of the rows fails.
> """

La libreria standard di Go usa questo metodo, ed in effetti può essere
visto come un problema.


Ciao  Manlio


Maggiori informazioni sulla lista Python