-1
People,
Before asking my question, below is an example of instrumentation code (incomplete purposely) on Android:
import android.content.Intent
import androidx.lifecycle.Lifecycle
import androidx.test.core.app.ActivityScenario.launch
import androidx.test.core.app.ApplicationProvider.getApplicationContext
import androidx.test.ext.junit.runners.AndroidJUnit4
import br.com.topoil.account.LoginActivity
import org.junit.Test
import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun loadActivity() {
val i = Intent(getApplicationContext(), LoginActivity::class.java)
var scenario = launch<LoginActivity>(i)
scenario.moveToState(Lifecycle.State.CREATED)
}
}
Suppose you put a breakpoint right on this line:
scenario.moveToState(Lifecycle.State.CREATED)
The behavior of this test will be as follows: Loginactivity will appear pretty on Android! And that’s exactly what I wanted, validate the layout. For this the test cannot "end" the life cycle, enter @After etc.
It’s clear that it breaks a branch and helps a lot to really see how Activity will be in the initial state (in this example) right after writing the Activity code and testing on a real device.
Since the instrumentation test has a defined life cycle: Before, Test and After, if you obviously don’t put the breakpoint right there and debug, Activity appears and disappears immediately (which is exactly what happens - and you’re right).
So the question is: Is there a way to test the layouts more efficiently in Android Studio and run a "mocked" Activity so that it enters an initial state and does not disappear, without the need to write an instrumentation test?
Personal thank you!
Thank you!!! : -D I will look calmly! Anyway, the "noodle" way quoted above helped me for a few times kakakakak. Of course, it’s not ideal, but boy I searched it huh! I’ll take a look at the Barista too! : -D Thanks for the tip my friend! great week for you!
– Mateus
Come on, thank you. Have this nice tutorial on the Docs, teaching how to implement: https://developer.android.com/guide/components/activities/testing
– Lucas Villa Verde