kilianc / base-golang

0 stars 1 forks source link

unit test using xgo #3

Closed xhd2015 closed 5 months ago

xhd2015 commented 5 months ago

This PR changes unit testing to use xgo.

xgo has the following features compared to gomonkey:

The xgo project: https://github.com/xhd2015/xgo.

To run the tests, ensure xgo has been installed:

go install github.com/xhd2015/xgo/cmd/xgo@latest

Result:

$ xgo test -v ./
=== RUN   TestFetchPeople
=== RUN   TestFetchPeople/should_return_an_error_when_url_is_empty
=== RUN   TestFetchPeople/should_return_an_error_when_it_fails
=== RUN   TestFetchPeople/should_return_a_list_of_people
=== RUN   TestFetchPeople/should_return_a_list_of_people_(un-mocked)
--- PASS: TestFetchPeople (0.06s)
    --- PASS: TestFetchPeople/should_return_an_error_when_url_is_empty (0.00s)
    --- PASS: TestFetchPeople/should_return_an_error_when_it_fails (0.00s)
    --- PASS: TestFetchPeople/should_return_a_list_of_people (0.00s)
    --- PASS: TestFetchPeople/should_return_a_list_of_people_(un-mocked) (0.06s)
=== RUN   TestFetchPeopleAsync
=== RUN   TestFetchPeopleAsync/should_send_error_trough_a_channel_when_failing
=== RUN   TestFetchPeopleAsync/should_send_results_trough_a_channel_when_succeeding
--- PASS: TestFetchPeopleAsync (0.00s)
    --- PASS: TestFetchPeopleAsync/should_send_error_trough_a_channel_when_failing (0.00s)
    --- PASS: TestFetchPeopleAsync/should_send_results_trough_a_channel_when_succeeding (0.00s)
PASS
ok      github.com/kilianc/base-golang  0.998s