2015-10-26 20:02 GMT+01:00 Perini Matteo <perini.mat...@gmail.com>: > Il 26/10/2015 20:02, Manlio Perillo ha scritto: > [...] >> >> E' l'unico modo di fare unit test. >> Il problema è che quel codice è sbagliato; non è il modo corretto di >> usare le classi! >> >> Il modo corretto è: >> >> def test_somma(): >> cc = CC(2, 4, 5) >> assert cc.somma() == 11 >> > Chiaro! > Grazie >
Un ultimo consiglio. 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]). Ciao Manlio _______________________________________________ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python