小编Fan*_*ver的帖子

Python unittest 计算测试次数

这是我第一次在学校作业中使用 Python 的单元测试。我基本上有一个 Circle 对象,我在其中使用 pyunit 来确保数据正确存储。

我注意到 Python 只计算测试用例的方法数量,而不是断言语句的数量。

例如,我想测试方法是否正常工作,尽管有 4 个断言语句,Python 仅将以下内容算作 2 个测试。这确实让我措手不及,因为 Java 的 JUnit 会计算断言语句的数量。

def test_xcrd(self): 
    self.assertTrue(self.point.xcrd() == 1) 
    self.assertFalse(self.point.xcrd() == 5)

def test_ycrd(self): 
    self.assertTrue(self.point.ycrd() == 2) 
    self.assertFalse(self.point.ycrd() == 10)
Run Code Online (Sandbox Code Playgroud)

python 中的“规范”是什么?每个方法应该只有一个断言语句吗?

python python-unittest

4
推荐指数
1
解决办法
4235
查看次数

标签 统计

python ×1

python-unittest ×1