Python'da Teste Giriş
Alexander Levin
Data Scientist
class Rectangle:
# Rectangle yapıcı (constructor)
def __init__(self, a, b):
self.a = a
self.b = b
# Alan yöntemi
def get_area(self):
return self.a * self.b
# Kullanım örneği
r = Rectangle(4, 5)
print(r.get_area())
>> 20
class RedRectangle(Rectangle):
self.color = 'red'
unittest - test otomasyonu için yerleşik Python çerçevesi (Python ile kurulur).unittest - yalnızca birim testleri için değildir.unittest
pytest
test_ ile başlayan betik ve fonksiyonları ararÜçüncü taraf paket (Python dağıtımından ayrı kurulmalıdır)
Daha az doğrulama yöntemi
Üs alma operatörü testi:
import unittest
# TestCase sınıfının bildirimi
class TestSquared(unittest.TestCase):
# Testin tanımı
def test_negative(self):
self.assertEqual((-3) ** 2, 9)
.assertEqual(), .assertNotEqual().assertTrue(), .assertFalse().assertIs(), .assertIsNone().assertIsInstance(), .assertIn().assertRaises()unittest - test otomasyonu için OOP tabanlı yerleşik Python çerçevesiunittest içinde bir test örneğiunittest.TestCase'den miras alan bir sınıf tanımlayınPython'da Teste Giriş