3.4 Assignment 6

Your sixth assignment requires that you have read and understand Mocking.

Overview

In this assignment, you will take a break from new feature development and revisit the GitHub issues feature you implemented in the previous assignment.

1 Mock GitHub client

Your first task is to implement a mock implementation of the GitHub client you created in the previous assignment. By definition of a mock, the implementation MUST implement all of the same features as the real GitHub client so that they can be used interchangeably.

If you haven't already, you will need to update the Issue Tracker's use of the GitHub client type to be an interface.

2 Mock unit tests

Add unit tests for the Issue Tracker business logic that interacts with your mock implementation of the GitHub client. You should be able to modify the client's behavior so that you can test the following:

  • 200 status code with an empty value response.
  • 200 status code with a non-empty value response.
  • 400 status code.
  • 404 status code.
  • 500 status code.

3 httptest unit tests

Now that you've seen how to write unit tests with a mock, we can add unit tests for the same criteria above (i.e. the status code cases), but this time by using the httptest package. This approach requires that you use an httptest.Server that responds to HTTP requests in test environments.

4 Discuss

Write up a short discussion that compares and contrasts the testing strategies you implemented here. What did you like about the mock approach? What were its trade-offs, if any? Similarly, what do you think about the httptest package, and what were its trade-offs? Is it better to use mocks or httptest? Explain.

Your discussion should be written in a docs/testing.md file and checked-in to your repository.

Submitting

Notify your mentor that you have created the pull requests in the issue-tracker repository. Your mentor will review your code and assign a grade before your next weekly check-in.