Wprowadzenie do testowania w Pythonie
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 – wbudowany framework Pythona do automatyzacji testów (instalowany razem z Python).unittest – nie tylko do testów jednostkowych.unittest
Python)pytest
test_Pakiet zewnętrzny (wymaga osobnej instalacji)
Mniej metod asercji
Test operatora potęgowania:
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 – wbudowany framework Pythona oparty na OOP do automatyzacji testówunittestunittest.TestCaseWprowadzenie do testowania w Pythonie