4 ms·
By authoring private structs with public constructors, you can get what you want out of this. Gets a bit messy with testing, but not impossible.
by venantius 8y ago
By authoring private structs with public constructors, you can get what you want out of this. Gets a bit messy with testing, but not impossible.
- thanatos_dem 8y agoIf you have your tests within the same package, they can access the private members of structs directly, which helps avoid some of the mess. If you’re in a different package things aren’t too bad if you have meaningfully abstracted interfaces. And with Go’s duck typing, even if you’re using another package that doesn’t have good abstraction, you can create your own interfaces with the functionality you need for mocking purposes.