doushi1510 2016-09-27 12:38
浏览 34

Golang中的集成测试-如何测试路由器和http.Handlers之间的链接?

I've been tinkering around with golang and I try to implement a little todo application which should grow with the time. My thoughts about the applications architecture are the following:

  • The main package sets up the server and integrates the "services/handler" of the other packages in it's router under the corresponding path prefixes.
  • Every "service" has its own handlers and routes them correctly

So I've started just with the main package and wrote some todo handlers. To test the API I've written some integration tests (request/response). Now, I've removed the todo logic from the main package into it's own. When I execute go test -cover it shows me just the coverage of the main.go, but not for the todo package. That leads me to the conclusion that each package has to test on it's own.

So I have not to test the API in the main package but the integration, that '/todos' ends up in the todo package and nothing more, is that right? How can I test that? And in the todo package I have to test:

  • The routing in the package
  • And with a response recorder the API implementation

Is that right too? So how can I test the routing on it's own? Is that possible?

Here is my git repository: https://github.com/fvosberg/mrsjenkins

Thanks in advance

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 连续两帧图像高速减法
    • ¥15 组策略中的计算机配置策略无法下发
    • ¥15 如何绘制动力学系统的相图
    • ¥15 对接wps接口实现获取元数据
    • ¥20 给自己本科IT专业毕业的妹m找个实习工作
    • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
    • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
    • ¥50 mac mini外接显示器 画质字体模糊
    • ¥15 TLS1.2协议通信解密
    • ¥40 图书信息管理系统程序编写