import unittest
class
teststringmethods
(unittest.testcase)
:def
test_upper
(self)
: self.assertequal(
'foo'
.upper(),
'foo'
)def
test_isupper
(self)
: self.asserttrue(
'foo'
.isupper())
self.assertfalse(
'foo'
.isupper())
deftest_split
(self)
: s =
'hello world'
self.assertequal(s.split(),
['hello'
,'world'])
# check that s.split fails when the separator is not a string
with self.assertraises(typeerror)
: s.split(2)
if __name__ ==
'__main__'
: unittest.main(
)
suite = unittest.testloader().loadtestsfromtestcase(teststringmethods)
unittest.texttestrunner(verbosity=2).run(suite)
通過自定義下面兩個方法,實現測試資料以及測試環境的準備及清理:
方法檢查點
assertequal(a, b)
a == b
assertnotequal(a, b)
a != b
asserttrue(x)
bool(x) is true
assertfalse(x)
bool(x) is false
assertis(a, b)
a is b
assertisnot(a, b)
a is not b
assertisnone(x)
x is none
assertisnotnone(x)
x is not none
assertin(a, b)
a in b
assertnotin(a, b)
a not in b
assertisinstance(a, b)
isinstance(a, b)
assertnotisinstance(a, b)
not isinstance(a, b)
assertraises(exc, fun, *args, **kwds)
fun(*args, **kwds) raises exc
assertraisesregexp(exc, r, fun, *args, **kwds)
fun(*args, **kwds) raises exc and the message matches regex r
assertalmostequal(a, b)
round(a-b, 7) == 0
assertnotalmostequal(a, b)
round(a-b, 7) != 0
assertgreater(a, b)
a > b 2.7
assertgreaterequal(a, b)
a >= b
assertless(a, b)
a < b
assertlessequal(a, b)
a <= b
assertregexpmatches(s, r)
r.search(s)
assertnotregexpmatches(s, r)
not r.search(s)
assertitemsequal(a, b)
sorted(a) == sorted(b) 也支援unhashable物件
assertdictcontainssubset(a, b)
a裡面所有的鍵值對都在b中存在
APP自動化測試框架
1.instrumentation instrumentation 2.uiautomator uiautomator 3.robotium 4.monkey monkey 是android中的乙個命令列工具,可以執行在模擬器裡或實際裝置中。它向系統傳送偽隨機的使用者事件流 如按鍵輸入 觸控螢幕輸入...
app自動化測試 appium
雙擊執行如下檔案 net4.5.1.exe 2 安裝node v6.11.4 x64.msi 3 安裝 安裝jdk1.8及以上版本。雙擊解壓 adt bundle windows x86 64 20140702.zip 配置環境變數 新增android home環境變數,配置sdk根目錄。andro...
自動化測試之六 自動化測試模型
from selenium import webdriver chrome driver path r c users administrator envs selenuimautotest lib site packages selenium webdriver chrome chromedriv...