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

Set up local unit testing in Scribe Android App #181

Closed
2 tasks done
albendz opened this issue Oct 9, 2024 · 7 comments
Closed
2 tasks done

Set up local unit testing in Scribe Android App #181

albendz opened this issue Oct 9, 2024 · 7 comments
Assignees
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 9, 2024

Terms

Description

Summary

Select unit testing and mocking frameworks for local unit tests in the Scribe Android application and add unit tests to the codebase.

Details

Local unit tests provide a way to test individual classes or functions at build time to verify expected functionality. For example, testing both branches of an if... else. These tests are faster than manual or automated UI tests and are particularly useful when refactoring to assert behavior is the same before and after refactoring.

Additional details on local unit tests: https://developer.android.com/training/testing/local-tests

As an Android application, JUnit is commonly used for local unit tests.

There are two versions of JUnit in use - JUnit 4 (legacy) and JUnit 5 (latest). Android testing dependencies only supports JUnit 4 and there is an additional third-party dependency you can add to use JUnit 5 instead: https://github.com/mannodermaus/android-junit5. Additionally, instrumentation tests for Android using Espresso require JUnit 4: https://developer.android.com/training/testing/instrumented-tests

If it is acceptable to add the third-party dependency to the project, I recommend JUnit 5.

Additional reading on JUnit 5 support for Android: android/android-test#224

Mocking is used to to mock or fake behavior of class dependencies to isolate the test scope. There are two candidate mocking frameworks for Android Kotlin:

MockK has slightly better support for mocking when writing Kotlin code but there isn't a significant difference between the two in terms of what they support. Mockito is more widely used as one of the more established Java test mocking frameworks.

Contribution

I'm happy to take this on as soon as the maintainers let me know which frameworks are preferred for this project. Feel free to assign to me when ready.

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

CC @angrezichatterbox for this conversation :) From my side, adding a dependency for JUnit 5 is not a problem and that sounds good to me. For MockK vs. Mockito, I'll take another look, but better developer experience definitely would be a factor, and that MockK is written in Kotlin (though I understand that the difference isn't as much as for iOS languages).

Really appreciate your willingness to help here, @albendz!

@growabeard
Copy link
Collaborator

I'd love to help contribute to tests, but I do see that @albendz is taking care of the addition of the framework. I have experience with JUnit 4&5, MockK, and Mockito.

@angrezichatterbox
Copy link
Member

I think MockK would be a good choice for our project. Since we are already working in Kotlin using MockK will give a better developer experience. Unlike Mockito, which requires additional dependencies for proper integration with Kotlin, MockK is specifically designed for Kotlin and doesn’t have those extra requirements. Additionally, MockK’s syntax is easier to read and maintain. Also Mockk has support for mocking final classes and methods.

I would love to hear what everyone else feels about this. @andrewtavis @growabeard @albendz

@andrewtavis
Copy link
Member

Sounds good to me, @angrezichatterbox! Thanks for the research effort! :)

So decision is JUnit 5 and MockK 😊

@andrewtavis
Copy link
Member

Assigning @albendz for adding these into the project, and then we can discuss how we want to structure implementing individual tests :)

@albendz
Copy link
Contributor Author

albendz commented Oct 10, 2024

Sounds good!

@andrewtavis
Copy link
Member

Closed by #188 🚀 @albendz will be making more issues for testing coming up :) From there the four of us can discuss implementation of those issues 😊

Thanks all!

@github-project-automation github-project-automation bot moved this from Todo to Done in Scribe Board Oct 13, 2024
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
Archived in project
Development

No branches or pull requests

4 participants