DocumentFileX icon indicating copy to clipboard operation
DocumentFileX copied to clipboard

[Question] Unit tests ?

Open RobbWatershed opened this issue 4 years ago • 10 comments

I'd like to contribute a few additions but, as there's no documentation and no design documents, I'm kinda afraid to break things without realizing it.

I guess you're testing new changes through your app, which is totally fine as far as you're concerned, but imo not enough for a library aimed at being reusable outside of that app.

=> Is there a way we could set up unit tests to detect any regression and somehow show how the API works ?

I'm not sure how to start, but I would definitely help enrich the first tests if you got a few of them running...

RobbWatershed avatar Sep 13 '21 12:09 RobbWatershed

I agree with you but I am also not sure how to start mainly because of the "maintaining URI" part. I think one option is to modify the sample app to test things out, but I have no idea how to implement it as unit tests at the moment.

You can just submit PR and modify codes however you want, seems like I'm the only one who is using this library seriously :joy:

tom5079 avatar Sep 13 '21 13:09 tom5079

By the way, even the official DocumentFile library is not properly tested :shrug:

this is all they're doing

tom5079 avatar Sep 13 '21 13:09 tom5079

OK. I think I found a way

The combination of MANAGE_EXTERNAL_STORAGE flag and android emulator github action should do the trick :tada:

tom5079 avatar Sep 13 '21 14:09 tom5079

By the way, even the official DocumentFile library is not properly tested 🤷

this is all they're doing

...and we know what it lead to 😆

Seriously, Google have done many outstanding things, but goddamn SAF is definitely not one of them 🤦

RobbWatershed avatar Sep 13 '21 18:09 RobbWatershed

You can just submit PR and modify codes however you want, seems like I'm the only one who is using this library seriously 😂

Well, I'm gonna do that PR anyway because the piece of code you got from avluis doesn't work on Android 11 (we just found out about that last week)

However, I still haven't abandoned the idea of externalizing file I/O to a library such as that one. It makes sense to join our forces to simplify that part of Android.

Please let me know when you have the first unit test running, I'll take some time to increase coverage 😉

RobbWatershed avatar Sep 13 '21 19:09 RobbWatershed

okay, I think I found a way MANAGE_EXTERNAL_STORAGE doesn't work for SAF :hankey: so we have to resort to use UiAutomation API to manually automate the permission granting process.

tom5079 avatar Sep 14 '21 08:09 tom5079

@RobbWatershed

I pushed the code to dev branch that grants permission automatically. Currently, it's quite limited (only supports SDK 21 and no CI support yet) but I'll figure them out shortly.

You can run the tests locally by running tests in sample/androidTest/ExampleInstrumentedTest.kt (yes, I should change the name too)

tom5079 avatar Oct 03 '21 11:10 tom5079

As far as i'm concerned, API21 is fine. I'll take a look and get back to you soon.

RobbWatershed avatar Oct 04 '21 12:10 RobbWatershed

@tom5079 Sorry for the delay, I've been focused on my roadmap for quite a while.

Just tested your new unit test successfuly. What you've done to enable permissions is devilish... but hey, it works, so no complaints here ! 😉

I'll post some newer tests soon. Thanks for the hard work !

RobbWatershed avatar Dec 04 '21 11:12 RobbWatershed

No problem, and thanks for your interest! Tell me whatever needs to be done with this library 😃

tom5079 avatar Dec 04 '21 11:12 tom5079