how does unit testing works in django? (with coverage)

Viewed 42

i am finding it kinda confusing to do unit testing especially with fields that has blank=True attribute or unique=True

look at this for example:

class TagTest(TestCase):
    def create(self):
        tag = models.Tag.objects.create(name='test')
        return tag
    def test_get(self):
        tag = self.create()
        self.assertIsInstance(tag, models.Tag)
        self.assertEqual(tag.name, tag.__str__())
        self.assertEqual(len(tag.name),4)class TagTest(TestCase):
    def create(self):
        tag = models.Tag.objects.create(name='test')
        return tag
    def test_get(self):
        tag = self.create()
        self.assertIsInstance(tag, models.Tag)
        self.assertEqual(tag.name, tag.__str__())
        self.assertEqual(len(tag.name),4)

look at coverage for example, it is telling me i am not covering the test case at all

enter image description here

1 Answers

I found the issue, it was because i needed to "run" coverage before actually generating html, so firstly: coverage run manage.py test app_name

then: coverage html

to generate new html.

Related