-
Notifications
You must be signed in to change notification settings - Fork 18
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
Consistency checks for dynamic strings, before adding "Frère Jacques" song. #88
Conversation
Compare the contents of our src/main/assets folder to our main translation strings.xml (both directions). Since soundset-translations are dynamically fetched, static inspections are powerless on them. We need to manually ensure all soundsets have a primary translation id, and that all `soundset_` translation ids apply to an existing asset folder.
Provides initial translations for those languages I'm comfortable with.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the new song, great addition. I also agree with the unit test principle here, and have done similar things in the past. For example, my libgdx based games try to ensure that there is no flakey translations, and the F-Droid project extensively thrashes out the translations to check for syntactic errors that the compiler wont pick up.
However, all the reflection in here is a bit hairy. If you are interested, I can add a commit on top of this that uses robolectric to allow accessing the actual Context
and Resources
objects from our app, but on the local JVM without the need for a running Android device. In practice, this results in a test API that levereages the Context.getString()
method.
Example of obtaining a reference to Resources
from the "real" (via whatever magic robolectric does) Context
: https://stackoverflow.com/a/58617596
Oh, I totally agree! This is the best I could come up with without additional dependencies, but it's definitely not up to my usual standards. To much "clever" and way too brittle. Feel free to add commits on top, I think your greater experience here could teach me a thing or two! 💙 I am very hesitant to add dependencies for this, because everything I could think of (e.g. Class path scanning with ClassGraph) feels like way overkill. However, I may have to accept that Android Context is a complex beast, which requires big guns to deal with. I'd be very happy with something more robust, but I am really running into my inexperience with the Android platform (PianOli is my first Android experience) . For example I've never heard of "robolectric" before. One concern I have with robolectric: is it compatible with JUnit5? The examples I saw all work with JUnit4, and the plugin I added for 5 doesn't seem very "industry standard". P.S. It may be good timing for context-mocking dependencies anyway. I'm running out of things that can be tested "pure java"-style. So far my refactoring managed to push context dependance "outwards" (Still good design, I think) , but that is reaching its own limits. |
For sure, it is a wild west out there. I believe robolectric is "industry standard" for lack of a better word. If you google "Android tests" you go to the official docs for running local tests on the JVM: https://developer.android.com/training/testing/local-tests#dependencies. Note how this has a comment mentioning "robolectric environment". And yes, it is still JUnit4. Perhaps that is why the aforementioned docs page has a dependency for JUnit4. However, a Google earlier showed that this seems likely to change, and so if we really want to stick with JUnit5, then we need For what it is worth, I agree that pushing |
So, some reading shows that robolectric has not been ported to junit5.
Robolectric is currently hard-coupled to the way junit4 does classloading. This mechanism could be ported to a junit5 extension, but nobody has prioritised this work in the last 6 years. I am not sure if this stackoverflow answer means that I could use the "vintage runner" for this specific test. However, I believethat would cost me the nice All in all, I'm not too fond of committing to a junit4-only framework just yet. Junit5 is soooo much nicer that I want to do some more research before giving it up. @pserwylo, how firm is your opposition to the specific forms of reflection? Maybe we can find a mutually-acceptable subset for now, and postpone the truly hairy things to a separate MR. To make my own hairyness-judgements explicit:
That leaves the two that I find actively ugly: the filesystem listers.
|
Time for bed now (reaaaaally, 3:09 in the night), but I wanted to bang out the Theme-as-Enum idea (#89). (Bonus: coding with a sleeping baby on your lap grants the Wife some uninterrupted sleep) |
Ever since @pserwylo added the song-player in #28, I've wanted to add Frère Jacques ("are you sleeping, brother John").
I am 99% sure it has translations for all European languages, as since it definitely has Spanish, English and Chinese, we reach probably 75% of all living humans on the planet.
However, adding songs requires updating quite a few hardcoded strings in multiple places. Since I dislike "you just have to know where" as an answer, especially for open source projects hoping for new contributors, I've added unit tests that check these implicit consistency rules.
It's definitely not perfect, but I think it covers most cases: