> For the complete documentation index, see [llms.txt](https://meetbill.gitbook.io/butterfly-project-doc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://meetbill.gitbook.io/butterfly-project-doc/project-framework/how/butterfly-test.md).

# 调试和测试之单元测试

## 单测例子

> test/handlers/test\_{app\_name}-{handler\_name}.py

```
from handlers.x import hello
from xlib import httpgateway

def test_hello():
    # 生成 req
    reqid="test_hello"
    ip = "127.0.0.1"
    wsgienv = {}
    req = httpgateway.Request(reqid, wsgienv, ip)

    # OK
    assert hello(req, "test_info") == ("OK", {'str_info': 'test_info'}, [('api_demo', '1.0.1')])
```
