What does this mean? ```Method beginSection in and...
# compose-desktop
c
What does this mean?
Copy code
Method beginSection in android.os.Trace not mocked. See <http://g.co/androidstudio/not-mocked> for details.java.lang.RuntimeException: Method beginSection in android.os.Trace not mocked. See <http://g.co/androidstudio/not-mocked> for details.
The link is broken. It happens when executing the JVM unit tests.
d
Do you see this log in gradle output? What command did you run? Can you please provide minimal reproducible sample on GitHub? And add text description on README.md how to reproduce that.
c
https://gitlab.com/opensavvy/decouple On the
main
branch, run
./gradlew check
One of the unit tests fails, in the test report the following stacktrace is shown:
Copy code
java.lang.RuntimeException: Method beginSection in android.os.Trace not mocked. See <http://g.co/androidstudio/not-mocked> for details.
	at android.os.Trace.beginSection(Trace.java)
	at androidx.compose.runtime.Trace.beginSection(ActualAndroid.android.kt:30)
	at androidx.compose.runtime.ComposerImpl.doCompose(Composer.kt:4495)
	at androidx.compose.runtime.ComposerImpl.composeContent$runtime_release(Composer.kt:3173)
	at androidx.compose.runtime.CompositionImpl.composeContent(Composition.kt:587)
	at androidx.compose.runtime.Recomposer.composeInitial$runtime_release(Recomposer.kt:950)
	at androidx.compose.runtime.CompositionImpl.setContent(Composition.kt:519)
Looking at it again, I'm not sure it's a desktop or android issue 😕
l
Android unit tests run on the local device's jvm, not in an actual Android environment. This seems like an android unit test based on the error. Can you tell which test?
Pulled the latest main. Looks like buttons_load_when_they_are_pressed fails on android (succeeds on jvm and js in general never plays nice with my machine, so not sure about js).
I would recommend avoiding Compose in android unit tests. You'll want to put it in androidInstrumentedTest instead. Not sure how to have commonTest do this, you may need androidInstrumentedTest and nonAndroidTest source sets.
d
I think this issue is not related to Compose desktop. And like Landry Norris says - it is better to launch Android tests on emulator.
c
Note that this test is not calling any Compose UI composable. These are all custom composables using a custom applier. Why would it not run on this platform if it's fine on others? Also, how can I stop this test from running on Android?
d
I was trying to run a task
./gradlew demo:jvmTest
and it works fine
You may run separate gradle tasks for Android and JVM
./gradlew jvmTest
for Desktop tests
c
So I can't use
./gradlew check
or
./gradlew allTests
with compose multiplatform?
l
You could if you mocked Trace. When you use commonTest, you're promising that all testing platforms support the code you're running. Clearly androidUnitTest doesn't support the Compose runtime well. I would make a separate source set that runs for jvm, js, and androidInstrumentedTest.
Maybe this would be best as an issue on the androidx bug tracker (not compose-multiplatform, as this is an android issue). I can see why you'd expect the runtime to run as-is in unit tests.
h
This is very easy to resolve. The
Trace
class is used for performance logging, so you can ignore it. In your test sources, create a class named android.os.Trace and implement a method named
beginSection
with the right signature https://cs.android.com/android/platform/superproject/+/master:frameworks/base/core/j[…]Trace.java;l=396;drc=1a382346dffa81623bcf4496fc41b9b83588e90e. You'll also need to implement endTrace and probably some other methods too.
c
Thanks, I'll look into it
150 Views