doukong1897 2019-05-02 13:54
浏览 122
已采纳

使用Golang进行功能测试

I have a webservice written in Golang.

I need to refactor it because it is poorly written.

I have seen Golang works with the format TestMethodName(t *testing.T). This is great for unit testing, but in my case, methods will change a lot because of the refactoring.

That's why I want to write functional testing, so that I can test each endpoint, and check that output has correct format, without being dependant of functions

How should I do it with Golang ?

Is there any framework that helps me with functional tests ? In another stack, like PHP / Laravel for instance, I can swap PostgreSQL with a SQLite, or In Memory testing, which is very practical for this kind of tests.

  • 写回答

1条回答 默认 最新

  • dsirr48088 2019-05-02 14:34
    关注

    You can test your API endpoints by using net/http/httptest package and mocking external dependencies.

    See example: https://golang.org/src/net/http/httptest/example_test.go

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?