Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing tip #15

Open
Gerifield opened this issue Jan 9, 2021 · 0 comments
Open

Testing tip #15

Gerifield opened this issue Jan 9, 2021 · 0 comments

Comments

@Gerifield
Copy link

Gerifield commented Jan 9, 2021

// TODO: Figure out how to test this

With interfaces! ;)
You could create a new interface (and probably some wrappers) with all the required file functions you need and replace the actual type with that in your code. The original struct will implement those instantly and you could re-write the function in your test.

Example:
https://medium.com/swlh/using-go-interfaces-for-testable-code-d2e11b02dea
(But I would not recommend to start the interface name with I... it's not java or php. :) )
Or: https://nathanleclaire.com/blog/2015/10/10/interfaces-and-composition-for-effective-unit-testing-in-golang/

@Gerifield Gerifield changed the title Testing tips Testing tip Jan 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant