Hi, I'd really like to be able to use my Model dat...
# compose
k
Hi, I'd really like to be able to use my Model data classes in my junit tests. (where I'm not running under compose). Is there a way to prevent the following error in this case? java.lang.IllegalStateException: Not in a frame at androidx.compose.frames.FramesKt.currentFrame(Frames.kt:180) at androidx.compose.frames.FramesKt.readable(Frames.kt:448) at androidx.compose.frames.FramesKt._readable(Frames.kt:456) at com.geeksville.mesh.model.Channel.getSettings(UIState.kt) at com.geeksville.mesh.model.Channel.getChannelUrl(UIState.kt:60) at com.geeksville.mesh.model.ChannelTest.channelUrlGood(ChannelTest.kt:11) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) ... at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
⏰ 1
m
what is the implementation of
getSettings()
on
Channel
?
👍 1
c
The most reliable way to modify an
@Model
object is to modify it in the main thread by, for example, posting a method to execute on that thread and waiting for it to complete. However, you can also open a frame in another thread using
open()
from
androidx.compose.frames
. For example, this is what the frames tests do here.
@Chuck Jazdzewski [G] that will work for me for now - thanks!
b
Forgive me for not diving into the details, but @Chuck Jazdzewski [G] shouldn’t whatever thread the unit tests are run on be considered the MainThread?
c
The main thread is the main thread from the perspective and Android. The unit test threads, unless requested, are not on the main UI thread. When I say main thread, I mean the UI thread not the test thread.