我正在Google应用引擎上创建一个应用程序,想知道是否有使用Python进行自动化测试的方法。
谢谢!
谢谢!
app.appspot.com
和我的app-test.appspot.com
。整个代码库都被设计为确保app-test.appspot.com
在外部系统中永远不会改变状态。app.appspot.com
复制到app-test.appspot.com
。这可能会变得混乱,因为数据存储的ID生成计数器不会更新,但它足够好用。app.appspot.com
上进行,后端实验则在app-test.appspot.com
上进行。whoami
.app.appspot.com进行实验。我们很少使用开发服务器,因为我们需要从数据存储中获取大量数据。resttest_dsl
,我们用它来描述测试,就像这样:client.GET('/').responds_access_denied()
client.GET('/', auth='user').responds_html()
client.GET('/admin').responds_access_denied()
client.GET('/admin', auth='user').responds_access_denied()
client.GET('/admin', auth='admin').responds_html()
client.GET('/artikel/').responds_with_html_to_valid_auth()
client.GET('/artikel/?q=Ratzfratz', auth='user').responds_html()
client.GET('/api/ic/v3/a/14600/03/zukunft.json').responds_with_json_to_valid_auth()
client.GET('/kunden/SC50313/o/SO1194829/', auth='user').responds_html()
client.GET('/api/masterdata/artikel/v2/artnr/14600/bild=s210').redirects_to('...')
主机名和凭据有默认值,但可以通过环境变量进行覆盖。我们曾经修复的大多数错误都有回归测试。我们使用Makefile
来驱动整个流程。例如:
deploy:
appcfg.py update -V dev-`whoami` -A app .
TESTHOST=dev-`whoami`.app.appspot.com make resttest
open http://dev-`whoami`.app.appspot.com/
部署始终是从中央git仓库进行的,流程如下:
deploy_production:
rm -Rf tmp
mkdir tmp
(cd tmp ; git clone git@github.com:user/app.git)
(cd tmp/app ; git checkout production ; make dependencies)
(cd tmp/app ; git show-ref --hash=7 refs/remotes/origin/production > version.txt)
appcfg.py update -V "v`cat tmp/app/version.txt`" -A app tmp/app
(cd tmp/huWaWi ; TESTHOST="v`cat version.txt`".app.appspot.com make resttest)
appcfg.py update -V production -A app tmp/app
appcfg.py backends -V production -A app tmp/huWaWi app
resttest.py
。如果失败,make
将停止执行。如果没有失败,则部署“生产版本”。我使用gaeunit - http://code.google.com/p/gaeunit/ - 它可能或可能不适合您的需求,但一旦它开始工作,添加测试用例就非常容易。我还添加了一个XML输出,以便我可以将结果传回JUnit分析器,以便我的Jenkins在代码检查后报告没有任何问题。
David Robinson 提到了开发单元测试。 如果你正在寻找使用 python 进行自动化用户(生产)测试,那么选择 selenium RC 或 selenium webdriver(改进版本和独立版)。
使用 selenium RC 可以做很多事情。