I just started reading a book name "Test-Driven Development with Python" and it's been attracting my attention immensely.
The best perk of doing test for every line of code is that your code will be clean and fruitful rather than messy and erroneous. Here is a sample code of python unit test from the book.
from django.test import TestCase
from django.urls import resolve
from django.httml import HttpRequest
from django.template.loader import render_to_string
from lists.views import home_page
class HomePageTest(self):
def test_uses_home_template(self):
response = self.client.get('/')
self.assertTemplateUsed(response, 'home.html')
The above tests whether the html request get brought in to send a response and whether that response locates 'home.html' or not.
Pretty darn clever, I must say!