2015-10-26 19:31 GMT+00:00 Manlio Perillo <manlio.peri...@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). 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 <http://xunitpatterns.com/Test%20Method.html>. Unfortunately, this makes the test an *Eager Test* <http://xunitpatterns.com/Assertion%20Roulette.html#Eager Test> (see Assertion Roulette on page X) because it verifies many test conditions <http://xunitpatterns.com/test%20condition.html>. This isn't a problem when all the tests are passing but it does lead to a lack of Defect Localization <http://xunitpatterns.com/Goals%20of%20Test%20Automation.html#Defect Localization> (see Goals of Test Automation) when one of the rows fails. """ Se si usa Nose: https://nose.readthedocs.org/en/latest/writing_tests.html#test-generators Se si usa PyTest: https://pytest.org/latest/parametrize.html -- . ..: -enrico-
_______________________________________________ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python