TJB*_*TJB 2 django abstract-class unit-testing testcase
我正在创建 Django 单元测试,并且有一些具有重复功能的非常相似的模型。但是存在一些差异,因此我创建了一个抽象 BaseTestCase 类,其他 TestCase 类从该类继承。它似乎工作正常,除了当从 BaseTestCase 类继承的 TestCase 完成运行测试时,Django 仍将尝试运行 BaseTestCase 类测试。Django 不应该不想在抽象的 BaseTestCase 上运行测试吗?我是否缺少某种类型的配置以确保不会发生这种情况?
测试用例布局
class BaseTestCase(SetupTestCase):
api = ""
def test_obj_list(self):
response = self.client.get(self.api)
self.assertTrue(response.status_code == 200)
def test_obj_create(self):
pass
def test_obj_retrieve(self):
pass
def test_obj_update(self):
pass
def test_obj_delete(self):
pass
class Meta:
abstract = True
class ChildTestCaseOne(BaseTestCase):
api = "/api/v0.1/path_one/"
class ChildTestCaseTwo(BaseTestCase):
api = "/api/v0.1/path_two/"
class ChildTestCaseThree(BaseTestCase):
api = "/api/v0.1/path_three/"
class ChildTestCaseFour(BaseTestCase):
api = "/api/v0.1/path_four/"
class ChildTestCaseFive(BaseTestCase):
api = "/api/v0.1/path_five/"
Run Code Online (Sandbox Code Playgroud)
这应该运行 25 个测试,5 个测试用例的 5 个测试,但它运行了 30 个。在为每个子类运行 5 个测试之后,它还为基本测试用例运行 5 个测试。
什么多重继承?
from django.test import TestCase
class BaseTestCase:
# ...
class ChildTestCaseN(BaseTestCase, TestCase):
# ...
Run Code Online (Sandbox Code Playgroud)
我在 Django 中找不到任何关于抽象测试用例的信息。你SetupTestCase从哪里得到的那门课?
| 归档时间: |
|
| 查看次数: |
729 次 |
| 最近记录: |