Úvod do testování v Pythonu
Alexander Levin
Data Scientist
class Rectangle:
# Constructor of Rectangle
def __init__(self, a, b):
self.a = a
self.b = b
# Area method
def get_area(self):
return self.a * self.b
# Usage example
r = Rectangle(4, 5)
print(r.get_area())
>> 20
class RedRectangle(Rectangle):
self.color = 'red'
unittest – vestavěný Python framework pro testování (instaluje se s Python).unittest – nejen pro unit testy.unittest
Python)pytest
test_Balíček třetí strany (nutno nainstalovat samostatně)
Méně metod tvrzení
Test operátoru umocňování:
import unittest
# Declaring the TestCase class
class TestSquared(unittest.TestCase):
# Defining the test
def test_negative(self):
self.assertEqual((-3) ** 2, 9)
.assertEqual(), .assertNotEqual().assertTrue(), .assertFalse().assertIs(), .assertIsNone().assertIsInstance(), .assertIn().assertRaises()unittest – OOP framework pro testování, součást Pythonuunittestunittest.TestCaseÚvod do testování v Pythonu