# Interfaces 101 : Testing with a Mock Interface Ep. 8

DevFeed: [Interfaces 101 : Testing with a Mock Interface Ep. 8](<https://devfeed.tech/articles/interfaces-101-testing-with-a-mock-interface-ep-8-22220.md>)

Original publisher: [Read original article](<https://www.ardanlabs.com/blog/2023/03/interfaces-101-testing-with-a-mock-interface-ep-8.html>)

Published: 2023-03-20T00:00:00Z

Content type: tutorial

Language: en

Sources: [William Kennedy](<https://devfeed.tech/sources/william-kennedy.md>)

Topics: [interface](<https://devfeed.tech/topics/interface.md>), [Test-driven development](<https://devfeed.tech/topics/tdd.md>), [mock api](<https://devfeed.tech/topics/mock-api.md>), [client library](<https://devfeed.tech/topics/client-library.md>), [Code Modularity](<https://devfeed.tech/topics/code-modularity.md>)

Tags: [api](<https://devfeed.tech/tags/api.md>), [client](<https://devfeed.tech/tags/client.md>), [go](<https://devfeed.tech/tags/go.md>), [golang](<https://devfeed.tech/tags/golang.md>), [health-check](<https://devfeed.tech/tags/health-check.md>), [http](<https://devfeed.tech/tags/http.md>), [http-roundtripper](<https://devfeed.tech/tags/http-roundtripper.md>), [interface](<https://devfeed.tech/tags/interface.md>), [interfaces](<https://devfeed.tech/tags/interfaces.md>), [mock](<https://devfeed.tech/tags/mock.md>), [mock-api](<https://devfeed.tech/tags/mock-api.md>), [testing](<https://devfeed.tech/tags/testing.md>), [tests](<https://devfeed.tech/tags/tests.md>), [transport](<https://devfeed.tech/tags/transport.md>), [unit-test](<https://devfeed.tech/tags/unit-test.md>), [unit-testing](<https://devfeed.tech/tags/unit-testing.md>), [unit-tests](<https://devfeed.tech/tags/unit-tests.md>), [video](<https://devfeed.tech/tags/video.md>), [watch](<https://devfeed.tech/tags/watch.md>)

## AI overview

The excerpt describes building a Go API client that makes an HTTP request and returns an error based on the server's response code, then testing it without a real server. A custom type implementing the relevant interface is used as the request transport so tests can specify the response code. The episode also recaps the design guidance that interfaces should describe needed behavior and stay small to support composability.

## Source excerpt

Introduction In episode 7, Miki discussed design considerations to keep in mind while creating interfaces in Go with the first idea he proposed being that an interface should represent what we need from a type, and not what is stored on the type. To add some clarity to this thought, Miki explained how the io.Reader and io.Writer interfaces each require one method to be implemented although the underlying concrete type may store more information. The second idea he proposed was that interfaces should be small, with less than 6 methods, to ensure your code remains composable.