I want to run some test adding and getting accounts using AccountManager but I want to do the operations in a new context without the account I already have in the emulator.
Is it possible to do that?
Example of my class
@RunWith(AndroidJUnit4::class)
class AccountTest {
private val ACCOUNT_TYPE = "com.android.account"
private lateinit var accountManager: AccountManager
@Before
fun init() {
accountManager = AccountManager.get(ApplicationProvider.getApplicationContext())
}
@Test
fun addAccountTest(){
val account = Account("test", ACCOUNT_TYPE)
val result = accountManager.addAccountExplicitly(account, null, null)
assertThat(result, `is`(true))
}
@Test
fun getAccountTest() {
val accountList = accountManager.getAccountsByType(ACCOUNT_TYPE).toList()
assertThat(accountList.size, `is`(0))
}
}