我正在创建Django单元测试,并且有一些具有重复功能的非常相似的模型。但是,有一些不同之处,所以我创建了一个抽象的BaseTestCase类,由其他TestCase类继承而来。除了当继承自BaseTestCase类的BaseTestCase完成运行测试时,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/"它应该运行25个测试,5个测试用例的5个测试,但它运行30个。在为每个子类运行了5个测试之后,它还为基本测试用例运行了5个测试。
发布于 2017-11-21 01:27:58
那多重继承呢
from django.test import TestCase
class BaseTestCase:
# ...
class ChildTestCaseN(BaseTestCase, TestCase):
# ...我在Django中找不到任何关于抽象测试用例的东西。你从哪里得到那个SetupTestCase类的?
https://stackoverflow.com/questions/47401578
复制相似问题