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

Add examples of tests using mocking with MockK #197

Open
2 tasks done
albendz opened this issue Oct 13, 2024 · 5 comments
Open
2 tasks done

Add examples of tests using mocking with MockK #197

albendz opened this issue Oct 13, 2024 · 5 comments
Labels
feature New feature or request hacktoberfest Included as a part of Hacktoberfest help wanted Extra attention is needed

Comments

@albendz
Copy link
Contributor

albendz commented Oct 13, 2024

Terms

Description

Summary

The Scribe Android app supports unit testing with JUnit and mocking with MockK. Right now there aren't any test examples using mocking.

Add an example test that uses mocking.

Note that this may require some refactoring if you find you can't mock certain things or you're mocking a lot. For example, you cannot mock getting environment variables so that can be extracted into a separate class that itself can be mocked. I encountered this issue when I was attempting to write a unit test for one of the Activity classes.

Additional details

Here are some details related to mocking for Android: https://developer.android.com/training/testing/local-tests#mocking-dependencies

MockK documentation: https://mockk.io/

Contribution

I can pick this up later if no one else gets to it before I'm free

@albendz albendz added the feature New feature or request label Oct 13, 2024
@andrewtavis andrewtavis added help wanted Extra attention is needed hacktoberfest Included as a part of Hacktoberfest labels Oct 13, 2024
@KesharwaniArpita
Copy link
Contributor

Hi @albendz I am interested in this issue!

@albendz
Copy link
Contributor Author

albendz commented Oct 23, 2024

@andrewtavis Could you take a look at assigning this to @KesharwaniArpita ?

@andrewtavis
Copy link
Member

Thanks for the ping, @albendz :)

@KesharwaniArpita, could we ask you to send along a plan for this issue and we'll give you the ok to implement it? Please let us know if you need some support :)

CC @angrezichatterbox

@KesharwaniArpita
Copy link
Contributor

HI @albendz @andrewtavis do you think if we should consider writing tests for the MainActivity using mockk to ensure the functionality works as expected without relying on actual dependencies? We can start by mocking components like SharedPreferences, we can verify that user preferences, such as dark mode settings, are correctly applied in the applyUserDarkModePreference() method. Does that sound good?

@angrezichatterbox
Copy link
Member

HI @albendz @andrewtavis do you think if we should consider writing tests for the MainActivity using mockk to ensure the functionality works as expected without relying on actual dependencies? We can start by mocking components like SharedPreferences, we can verify that user preferences, such as dark mode settings, are correctly applied in the applyUserDarkModePreference() method. Does that sound good?

Yes, It sounds good to me. You could write tests for the Main Activity as an example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request hacktoberfest Included as a part of Hacktoberfest help wanted Extra attention is needed
Projects
Status: Todo
Development

No branches or pull requests

4 participants