How to write simple unit test in django

Success Run test file
==============

tests.py
=====

from django.test import TestCase

# Create your tests here.
class TestStringMethods(TestCase):

    def test_upper(self):
        self.assertEqual('foo'.upper(), 'FOO')

    def test_isupper(self):
        self.assertTrue('FOO'.isupper())
        self.assertFalse('Foo'.isupper())



Success Run test file
==============

$./manage.py test




Creating test database for alias 'default'...
..
----------------------------------------------------------------------
Ran 2 tests in 0.664s

OK
Destroying test database for alias 'default'...













---------------------------





Failed Run test file

============

tests.py
=====
from django.test import TestCase

# Create your tests here.
class TestStringMethods(TestCase):

    def test_upper(self):
        self.assertEqual('foo', 'FOO')

    def test_isupper(self):
        self.assertTrue('FOO'.isupper())
        self.assertFalse('Foo'.isupper())


Failed Run test file
============

$./manage.py test

Creating test database for alias 'default'...
.F
===============================================
FAIL: test_upper (employee.tests.TestStringMethods)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/sanu/raghu/imei/employee/tests.py", line 7, in test_upper
    self.assertEqual('foo', 'FOO')
AssertionError: 'foo' != 'FOO'

----------------------------------------------------------------------
Ran 2 tests in 0.720s

FAILED (failures=1)
Destroying test database for alias 'default'...






Comments

Popular posts from this blog

AttributeError: Got AttributeError when attempting to get a value for field `abc` on serializer `PfleSerializer`. The serializer field might be named incorrectly and not match any attribute or key on the `QuerySet` instance. Original exception text was: 'QuerySet' object has no attribute 'abc'.

ImportError: No module named regex