django单元测试

django单元测试,第1张

django单元测试 一、django单元测试

在tests.py目录编写单元测试内容
创建子类django.test.TestCase,内容如下:

import datetime
from django.test import TestCase
from django.utils import timezone
from .models import Question

class QuestionModelTests(TestCase):

    def test_was_published_recently_with_future_question(self):
        """
        was_published_recently() returns False for questions whose pub_date
        is in the future.
        """
        time = timezone.now() + datetime.timedelta(days=30)
        future_question = Question(pub_date=time)
        self.assertIs(future_question.was_published_recently(), False)
二、运行测试

在pycharm的Terminal输入执行命令:

python manage.py test poll


其中poll是项目名称

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5436960.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-11
下一篇 2022-12-11

发表评论

登录后才能评论

评论列表(0条)

保存