I've just added support for foldables to my playgr...
# compose
t
I've just added support for foldables to my playground app and now my instrumentation tests are failing because what was opening a new screen before now just show in the other screen of the foldable, which is fine. My question is, what's the recommended approach for testing these different setups?
s
Haven’t tried it myself, but maybe you can use test harness https://google.github.io/accompanist/testharness/ to provide your tests with different sizes and provide different assertions depending on them?
t
I thought about it but they say it's not really suitable for production. I would see it as a good option for testing individuals compostables in different configuration maybe. What I did instead was adding a test tag that would allow me to identify if the screen is split or single and run the test accordingly. This way I depend on the device that's running it, which maybe not be the best approach. I'm still open for suggestions, maybe I should give a try to TestHarness.
s
Yeah I understand what you mean, as I said I’ve never used it myself so I can’t really vouch for it. I just saw it recently and thought it may be useful. If you do figure something out please do let us know here, I am curious.
a
A rough summary of the current options that I can think of: • Adjust your test to be aware of the environment it is running on, and perform different logic and assertions. The downside is that the test gets more complicated, and you need to run the test across different devices to get full test coverage • Run a different subset of tests on different devices. This keeps the tests simpler, but with a downside of an overhead of different test groups, that are conditionally run based on different devices. There is also still the downside of needing to run the tests across a set of devices to get full test coverage • Use TestHarness to set a specific size for the component under test. The upside is you can run tests across different sizes (even ones that are larger than the device being used to test), so the logic remains simple, and you can have a single suite of tests that run on various devices If you try out TestHarness and have feedback or find issues, I’d be super interested to hear how it goes!
One of the main reasons for creating
TestHarness
was for this situation, to be able to say “render this component/screen at 800dp by 500dp, and verify that this is the behavior”, instead of having to implicitly depend on the emulator being used to run the test
That code would look something like
Copy code
@Test
fun example() {
    composeTestRule.setContent {
        TestHarness(size = DpSize(800.dp, 500.dp)) {
            MyComponent() // will be rendered at 800dp by 500dp, even if the window is smaller
        }
    }
}
s
Okay so it is made for this sort of use-case, good to know! I’d definitely give it a try if I were you Tiago 😊
t
Thanks @Alex Vanyo! I guess
TestHarness
is the way to go to be able to test all the cases in a single device, so I'll update my test to run with it. I'll let you know if there's any feedback or issues 😄