Python में Testing का परिचय
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 - टेस्ट ऑटोमेशन के लिए बिल्ट-इन Python फ्रेमवर्क (Python के साथ इंस्टॉल आता है)।unittest - केवल यूनिट टेस्ट तक सीमित नहीं।unittest
Python डिस्ट्रीब्यूशन के साथ इंस्टॉल)pytest
test_ से शुरू होने वाले स्क्रिप्ट/फंक्शन ढूँढता हैथर्ड-पार्टी पैकेज (Python डिस्ट्रीब्यूशन से अलग इंस्टॉल करना होता है)
कम assertion मेथड्स
Exponentiation ऑपरेटर का टेस्ट:
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-आधारित बिल्ट-इन Python फ्रेमवर्कunittest में टेस्टिंग का इंस्टेंसunittest.TestCase से इनहेरिट करती क्लास घोषित करेंPython में Testing का परिचय