unittest中常用的几个断言

a.相等

(a==b)内容一样,类型一致

from init import *
import unittest class Baidu_Title(Info): def test_baidu_title(self):
print(self.driver.title)
self.assertEqual(self.driver.title, "百度一下,你就知道") if __name__ == "__main__":
unittest.main(verbosity=2)

  

b.布尔类型(bool)

assertTrue和assertFalse

例如:判断输入框是否可写

from init import *
import unittest class Baidu_Title(Info): def test_baidu_input(self):
su = self.driver.find_element_by_id("kw")
self.assertTrue(su.is_enabled())
# self.assertFalse(su.is_enabled()) if __name__ == "__main__":
unittest.main(verbosity=2) 
c.包含

assertIn判断是否包含在里面

from init import *
import unittest class Baidu_Title(Info): def test_baidu_title(self):
self.assertIn("百度", self.driver.title) if __name__ == "__main__":
unittest.main(verbosity=2)

  

上一篇:.NET面向对象特性之封装


下一篇:js中数组方法大全