简化了web服务的测试。

webunit2的Python项目详细描述


webunit2Richard Jones’ webunit的精神继承者,但决不是叉子。这个 图书馆从一开始就建起来了,里面有文件和 测试。也是hosted on GitHub, 很容易叉开。

文档

Documentation is available on PyPi.

您也可以自己构建文档。确保安装了狮身人面像 通过运行:

$ easy_install -U sphinx

然后,克隆存储库,cd并运行:

$ python setup.py build_sphinx

文档位于build/sphinx/html

开始

开始真的很容易。你只需要执行 webunit2.testcase.Testcase并开始编写单元测试。

import webunit2

class TestMyApp(webunit2.TestCase):

    def __init__(self):
        # You aren't required to initialize the base class here, but it
        # makes dealing with subsequent requests easier--because they can
        # be relative paths!
        webunit2.TestCase.__init__(self, "http://myapp.com")

    def test_some_url(self):
        # Just do a normal get
        self.get('/somepath')

        # Lets post some data
        self.post('/somepath', post_params={"key": "value"})

        # No helper function for your HTTP method?  No problem!
        self.make_request("HEAD", "/somepath")

当然,因为这是一个单元测试框架,您可能会 很多断言——特别是在内容方面。那也很容易!

def test_for_content(self):
    # Assert the word `hippo` appears in the content.
    self.get_assertContent('/something', content="hippo")
    # Assert that the `X-Customheader` header was set.
    self.get_assertHeader('/something', 'X-Customheader')

如果其中任何一个失败(即返回码不是200或内容失败 不包含河马,AssertionError将正常筹集。以及 当然,如果需要检查响应上的多个值,则 assert*函数直接在响应上可用。例如, 以上内容可以重写为:

def test_for_content_resp(self):
    resp = self.get('/something')
    # Assert the word `hippo` appears in the content.
    resp.assertContent("hippo")
    # Assert that the `X-Customheader` header was set.
    resp.assertHeader('X-Customheader')

这也允许您将更多的断言链接在一起,即检查 标题、饼干等。这些都是all设计用来简化测试,所以 如果您有建议或投诉…

贡献

源代码是hosted on Github, 这使它成为一个叉和贡献。Please submit issues using the GitHub tracker!我喜欢得到 反馈,我强烈建议您提交功能和/或错误的罚单。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Android同步不同页面上的按钮   java评测每个类收集的垃圾对象实例数   java(Spring MVC+Hibernate 4+Test 4)自动连线DAO返回NULL   java Android编辑文本和虚拟键盘   java Selenium与BrowserMobProxy   JAVAlang.NoClassDefFoundError:com/sun/jersey/spi/inject/Errors$关闭原因?   java为什么在我成功登录后仍然会出现“不正确的帐户或密码或用户类型”   安卓应用程序在重新启动java时崩溃。网UnknownHostException:无法解析主机   多线程在Java中同步共享静态对象的正确方法是什么?   未调用自定义注释的java类验证(约束类)   java如何将指定目录的存档文件放入所需位置?   java如何识别Selenium中的每个编辑文本字段,如果它们的Xpath都相同   使用gwtmockito/mockito的java简单单选按钮单元测试?