I have written multiple test cases in an Android project but I want to execute test cases one after another. That means sequential execution need to occur.
When the first test case is complete then another test case will be executed For example if we have two screens Login and Home Page then after the successful test case of the Login it should execute test case for Home Page
I am a beginner for the Unit testing. I have tried this but not working.
How this will be possible? Here is my code:
MainActivity
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
supportFragmentManager.beginTransaction().add(R.id.container, ListFragment()).commitAllowingStateLoss()
}
}
Test Case for Main screen
MainActivityTest
@RunWith(AndroidJUnit4::class)
class MainActivityTest {
@get: Rule
var signInActivityTestRule = ActivityTestRule(MainActivity::class.java)
private var signInActivity: MainActivity? = null
@Test
fun testEventFragment() {
signInActivity = signInActivityTestRule.activity
val container = signInActivity!!.findViewById<FrameLayout>(R.id.container)
Assert.assertNotNull(container)
val fragment: Fragment = ListFragment()
signInActivity!!.supportFragmentManager.beginTransaction().add(container.id, fragment).commitAllowingStateLoss()
getInstrumentation().waitForIdleSync()
val jUnitCore = JUnitCore()
val computer = Computer()
jUnitCore.run(computer, ListFragmentTest::class.java)
}
}