Python中的assertGreaterEqual()是单元测试库函数,用于单元测试中以检查第一个给定值是否大于或等于第二个值。此函数将使用三个参数作为输入,并根据断言条件返回布尔值。
此函数检查第一个给定值是否大于或等于第二个值,如果是,则返回true,否则,如果第一个值不大于或等于第二个值,则返回false。
用法:assertGreaterEqual(first, second, message=None)
参数:assertGreaterEqual()接受以下三个参数的说明:
- first:第一个输入值(整数)
- second:第二个输入值(整数)
- message:作为测试消息失败时显示的消息的字符串语句。
下面列出的示例说明了给定assert函数的正负测试用例:
例:
Python3
# test suite
import unittest
class TestStringMethods(unittest.TestCase):
# negative test function to test if values1 is greater or equal than value2
def test_negativeForGreaterEqual(self):
first = 4
second = 5
# error message in case if test case got failed
message = "first value is not greater or equal than second value."
# assert function() to check if values1 is greater or equal than value2
self.assertGreaterEqual(first, second, message)
if __name__ == '__main__':
unittest.main()
输出:
F
======================================================================
FAIL:test_negativeForGreaterEqual (__main__.TestStringMethods)
———————————————————————-
Traceback (most recent call last):
File “p1.py”, line 13, in test_negativeForGreaterEqual
self.assertGreaterEqual(first, second, message)
AssertionError:4 not greater than or equal to 5:first value is not greater or equal than second value.———————————————————————-
Ran 1 tests in 0.000sFAILED (failures=1)
范例2:
Python
# test suite
import unittest
class TestStringMethods(unittest.TestCase):
# positive test function to test if values1 is greater than or equal to value2
def test_positiveForGreaterEqual(self):
first = 4
second = 4
# error message in case if test case got failed
message = "first value is not greater or equal than second value."
# assert function() to check if values1 is greater or equal than value2
self.assertGreaterEqual(first, second, message)
if __name__ == '__main__':
unittest.main()
输出:
.
———————————————————————-
Ran 1 test in 0.000sOK
相关用法
- Python unittest assertNotIn()用法及代码示例
- Python unittest assertNotEqual()用法及代码示例
- Python unittest assertFalse()用法及代码示例
- Python unittest assertIsNot()用法及代码示例
- Python unittest assertIs()用法及代码示例
- Python unittest assertIsNone()用法及代码示例
- Python unittest assertIsNone()用法及代码示例
- Python unittest assertIsNotNone()用法及代码示例
- Python unittest assertEqual()用法及代码示例
- Python unittest assertIn()用法及代码示例
- Python unittest assertNotIsInstance()用法及代码示例
- Python unittest assertIsInstance()用法及代码示例
- Python unittest assertAlmostEqual()用法及代码示例
- Python unittest assertNotAlmostEqual()用法及代码示例
- Python unittest assertLessEqual()用法及代码示例
- Python unittest assertGreater()用法及代码示例
- Python unittest assertTrue()用法及代码示例
- Python unittest assertLess()用法及代码示例
- Python Wand function()用法及代码示例
注:本文由纯净天空筛选整理自Shivam.Pradhan大神的英文原创作品 Python – assertGreaterEqual() function in unittest。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。