Django單元測試與搜尋引擎

HuangZhang_123發表於2018-05-07

----------歡迎加入學習交流QQ群:657341423

Django單元測試
在某App的test.py編寫測試類

from django.test import TestCase
from django.test import Client
from .models import MyUser
# Create your tests here.
class MyUserTest(TestCase):
    # 新增資料
    @classmethod
    def setUpTestData(cls):
        MyUser.objects.create(username='test',
                       password='test',mobile='13111111111')

    # 測試用例
    def test_MyUser_models(self):
        result = MyUser.objects.get(username='test')
        self.assertEquals(result.mobile, '13111111111')
        self.assertTrue(result.password)

	# 測試用例
    def test_login(self):
        c = Client()
        c.login(username='test', password='test')



搜尋引擎
傳送門
官方文件