Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

How do you test services? #39

Open
mdelgadov opened this issue Apr 18, 2023 · 0 comments
Open

How do you test services? #39

mdelgadov opened this issue Apr 18, 2023 · 0 comments

Comments

@mdelgadov
Copy link

I'm trying to do TDD but I'm finding it hard to deal with Preferences and Shell.Current objects that can't be injected and are created by Maui at running time.
I reviewed your brilliant application and found that you access all of them through services, freeing the View Models of references.

But, isn't it just passing the buck? At the end, the services aren't tested. I can test MVVM fine, but not Services.

Is that the case? You don't have a way to test your services in your code?

To illustrate:
This comes from the Settings Service:

public string AuthAccessToken
{
get => Preferences.Get(AccessToken, AccessTokenDefault);
set => Preferences.Set(AccessToken, value);
}

Now, I don't know a way to mock or stub the Preferences static class in the last two lines. If I want to test the service, I can't, because the Preferences static object is not injected but created behind the scenes.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant