设计用例测试下面的python程序def do_你能变形python的unittest测试用例吗?
^{} library被設計為采用您編寫的測試方法和一些數據場景,為(test method×scenario)的每個組合生成單獨的測試用例。在
例如:import unittest
import testscenarios
from .. import system_under_test
class foo_TestCase(testscenarios.WithScenarios, unittest.TestCase):
""" Test cases for `foo` function. """
scenarios = [
('purple': {
'wibble': "purple",
'expected_count': 2,
'expected_output': "Purple",
}),
('orange': {
'wibble': "orange",
'expected_count': 3,
'expected_output': "Orange",
}),
('red': {
'wibble': "red",
'expected_count': 1,
'expected_output': "Red",
}),
]
def test_has_expected_vowel_count(self):
""" Should give the expected count of vowels. """
vowel_count = system_under_test.foo(self.wibble)
self.assertEqual(self.expected_count, vowel_count)
def test_sets_expected_output(self):
""" Should set the output to the expected value. """
system_under_test.foo(self.wibble)
self.assertEqual(self.expected_output, system_under_test.output)
當測試發現發生時,foo_TestCase類將為測試運行程序生成6個測試。它們的名稱將用方案名稱注釋,因此生成的測試報告區分每個特定的測試用例:
^{pr2}$
如果您需要的話,可以使用更多的靈活性—請參閱testscenarios文檔—但是上面的內容演示了我在大多數情況下是如何使用它的。在
總結
以上是生活随笔為你收集整理的设计用例测试下面的python程序def do_你能变形python的unittest测试用例吗?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql语句 查询前5个_MySQL
- 下一篇: python字典定义方式_Python字