Skip to content
This repository has been archived by the owner on Mar 25, 2023. It is now read-only.

Add Mock (Test Double) Functions to speed up Dev/Testing #28

Closed
1 task
nelsonic opened this issue May 25, 2022 · 4 comments
Closed
1 task

Add Mock (Test Double) Functions to speed up Dev/Testing #28

nelsonic opened this issue May 25, 2022 · 4 comments
Assignees
Labels
chore a tedious but necessary task often paying technical debt documentation Improvements or additions to documentation help wanted Extra attention is needed priority-2 Second highest priority, should be worked on as soon as the Priority-1 issues are finished T2h Time Estimate 2 Hours

Comments

@nelsonic
Copy link
Member

At present when I run the tests on the gitea-demo dwyl/gitea-demo#5 they fail and have poor coverage:
image

This will be the case in any app that consumes the gitea package.

Todo

  • Add test double / mock functions for each of the un-tested functions
@nelsonic nelsonic added documentation Improvements or additions to documentation help wanted Extra attention is needed priority-2 Second highest priority, should be worked on as soon as the Priority-1 issues are finished chore a tedious but necessary task often paying technical debt T2h Time Estimate 2 Hours labels May 25, 2022
@nelsonic nelsonic self-assigned this May 25, 2022
@SimonLab
Copy link
Member

SimonLab commented May 25, 2022

I find working with the tests difficult at the moment. We have a few issues linked to the mocks:

And to make sure all the "path" for the return of functions are covered I need to write specific mocks. This might get more complicated when we add more features in the package.

For this specific issue, I would first remove/reduce the mock and run the tests directly on an instance of gitea. This would allow us to have the library tested again a "real" environment and to spot any errors for example if a new Gitea version break some api.
Then I would let the application using the gitea dependency (ex: gitea-demo) mock the Gitea functions used. This would allow the application to define what to do when calling Gitea function and not having it define in Gitea dependency itself.
@nelsonic let me know what you think, I'm happy to try this steps, I know it will require a bit more work but I think it will make implemention/changes much easier later on.

@nelsonic
Copy link
Member Author

@SimonLab to be clear: I 100% agree. I detest mocks!!
Mocks are like "fake friends"; they tell us what we want to hear not the truth!
If it were up to me we would never mock anything and would always run real-world end-to-end tests.

My reasoning for having mocks in this type of HTTP/Network-dependent package is two-fold:

  1. Tests pass (with coverage) on GitHub CI where we haven't been able to setup the SSH key (on CI) to git clone or git push to the Gitea Server.
  2. Let the downstream module where we (or other devs using the gitea package) might not want to hit the actual server endpoints during tests/CI both because of time (tests taking much longer to run) or just being offline ...

Again, I 100% agree with running the tests with mock: false I do this on localhost. ✅
But in the demo app and other "consumer" apps, I don't see much choice. Do you? 🤷‍♂️

If there is a way around this, we should totally explore it. 🔍

@nelsonic
Copy link
Member Author

cheekily included in #36 🙊

@nelsonic
Copy link
Member Author

Tests now pass in the demo (mock: true) with 100% coverage on CI: dwyl/gitea-demo#5
image

Again, I detest Mocks. But if it means my tests run faster on localhost and pass on CI ... then #NecessaryEvil. 🙄

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
chore a tedious but necessary task often paying technical debt documentation Improvements or additions to documentation help wanted Extra attention is needed priority-2 Second highest priority, should be worked on as soon as the Priority-1 issues are finished T2h Time Estimate 2 Hours
Projects
None yet
Development

No branches or pull requests

2 participants