Skip to content

Conversation

@fsladkey
Copy link
Contributor

Hi there!

As mentioned in #382, there aren't currently any samples (here or elsewhere) for how to use the androidx-test-ext:junit-gtest library, so I've put together a minimal sample project.

This is not a particularly realistic example, but hopefully it will still be helpful as a guide for wiring everything together and could perhaps be expanded on in the future.

I based this on ui/screenshot/ScreenshotSample, to avoid deviating too far from the other samples. But definitely let me know if there's anything I should fix.

I'm not sure the directory placement is appropriate, I made a new directory called "native" because I wasn't sure the best way to categorize this sample (it's running unit tests, but on device 🤔). So just let know if there is a better spot for it.

Hope this is helpful! Thanks! :)

@utzcoz
Copy link
Contributor

utzcoz commented May 23, 2022

@fsladkey Thanks for adding this sample for junit-gtest. It's awesome. Hi @brettchabot , what about helping to review this PR?

@utzcoz
Copy link
Contributor

utzcoz commented May 23, 2022

@fsladkey Maybe you need to add a managed device configuration for this sample, see #434.

Copy link
Collaborator

@brettchabot brettchabot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Fred!

Consider adding a README.md.

Also consider adding this project to projects.conf so it gets tested on androidx.test library updates.

I don't have a strong opinion on location but I think unit/BasicNativeAndroidTest would work too.

import org.junit.runner.RunWith

@RunWith(GtestRunner::class)
@TargetLibrary(libraryName = "adder-test")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about adding a Java version sample too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea, unfortunately there's currently a limitation where only one GtestRunner can exist at a a time so duplicating the test in Java throws an error. It would be great to remove this limitation and I'm hoping to but until then I'm not sure there's a clean way to have both.

I'd also be happy to replace the Kotlin sample with Java is you think that's better. They are nearly identical anyway.

@fsladkey
Copy link
Contributor Author

Thanks for the reviews folks! I think I addressed most of the comments and added a readme. I also tested the ./test_all.sh script and although I had to comment out some other projects (maybe something in my environment is wrong) it looks like this project should now be tested by that script and is passing.

@brettchabot brettchabot merged commit c45a0ad into android:main May 24, 2022
}
apply plugin: 'kotlin-android'

android {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't gotten around to filing a bug for this, but consumers of junit-gtest actually need to exclude some cruft that's included in the AAR or it will end up in the APK: https://github.com/DanAlbert/ndk-app-template/blob/6f46d2f49e68d20c102eb2122262716564f191d2/app/build.gradle#L42-L48 (in this example you don't want to exclude libc++_shared since this build is using libc++_shared; the example I linked uses the static lib)

Not sure if you want to include that workaround in this example, or fix the bug before submitting this. I'm fine either way.

The rest LGTM though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants