Próbuję osiągnąć 100% pokrycie podstawowego modułu python. Używam modułu coverage.py Neda Batcheldera do przetestowania go.Czy funkcja coverage.py mierzy definicje funkcji i klas?
1 class account(object):
2 def __init__(self, initial_balance=0):
3 self.balance = initial_balance
4 def add_one(self):
5 self.balance = self.balance + 1
To są testy.
class TestAccount(unittest.TestCase):
def test_create_edit_account(self):
a = account1.account()
a.add_one()
Oto, co otrzymałem raport o zasięgu.
COVERAGE REPORT = Name Stmts Miss Cover Missing ----------------------------------------------------- __init__ 1 1 0% 1 account1 5 3 40% 1-2, 4 account2 7 7 0% 1-7
Jak widać, wiersze 1-2 i 4 nie są objęte definicją. Pozostałe linie są wykonywane.
! Dzięki za pomoc. Zadziałało. – praveen