如何进行单元测试单元测试测试用例
我有一个 unittest.TestCase 子项,它定义了几个特定于域的断言检查。 我想运行一些单元测试来对该功能进行单元测试,以控制未来更新中的一切工作。
class MyBaseTestCase(unittest.TestCase):
def setUp(self):
...
def tearDown(self):
...
def run(self, result):
...
def assertSpec(self, condition, message):
...
我想在其他单元测试中实例化 MyBaseTestCase,如下所示:
class TestBase(unittest.TestCase):
def test_assertSpec(self):
self.testclass = MyBaseTestCase()
self.assertRaises(AssertionError, self.testclass.assertSpec, False)
我遇到了多个不同的错误,所以我的问题是对自定义单元测试函数进行单元测试的常见做法是什么?
在执行此操作时, 帮助:
$ jython
>>> import sys
>>> sys.version
'2.5.2 (Release_2_5_2:7206, Mar 2 2011, 23:12:06) \n[Java HotSpot(TM) Server VM (Sun Microsystems Inc.)]'
I have a unittest.TestCase child, which defines several domain specific assert Checks.
I would like to run some unittests to unittest this functionality to control that everything work on future updates.
class MyBaseTestCase(unittest.TestCase):
def setUp(self):
...
def tearDown(self):
...
def run(self, result):
...
def assertSpec(self, condition, message):
...
I want to instantiate MyBaseTestCase in other unit test, like this:
class TestBase(unittest.TestCase):
def test_assertSpec(self):
self.testclass = MyBaseTestCase()
self.assertRaises(AssertionError, self.testclass.assertSpec, False)
I'm encountering multiple different errors, when doing this, so my question is what is a common practice for unittesting custom unittest functions?
In case it helps:
$ jython
>>> import sys
>>> sys.version
'2.5.2 (Release_2_5_2:7206, Mar 2 2011, 23:12:06) \n[Java HotSpot(TM) Server VM (Sun Microsystems Inc.)]'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定是否有任何 Jython 特定的东西会破坏这个,但我会做这样的事情:
Not sure if there's anything Jython specific that would break this, but I would do something like this: