This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import androidx.test.core.app.ApplicationProvider | |
@RunWith(AndroidJUnit4::class) | |
class DatabaseTest { | |
private lateinit var database: MainDatabase | |
@Before | |
fun setUp() { | |
val context = ApplicationProvider.getApplicationContext<Context>() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CarTest { | |
private lateinit var car: Car | |
@Before | |
fun setUp() { | |
car = Car() | |
} | |
@Test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Busca objeto que representa o device e vai para Home do smartphone | |
mDevice = UiDevice.getInstance(getInstrumentation()); | |
mDevice.pressHome(); | |
// Busca um componente clicável através do seu content description. | |
// Nesse caso o botão que aciona o launcher do smartphone. | |
UiObject allAppsButton = mDevice.findObject(new UiSelector().description("Apps")); | |
// Executa um click no botão anterior para carregar o launcher. | |
allAppsButton.clickAndWaitForNewWindow(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void greeterSaysHello() { | |
onView(withId(R.id.name_field)).perform(typeText("Steve")); | |
onView(withId(R.id.greet_button)).perform(click()); | |
onView(withText("Hello Steve!")).check(matches(isDisplayed())); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(AndroidJUnit4.class) | |
public class InstrumentedUnitTest { | |
private final String prefName = "TEST_PREF"; | |
@Test | |
public void test_sharedPref(){ | |
Context mContext = InstrumentationRegistry.getContext(); | |
SharedPreferences mSharedPreferences = mContext.getSharedPreferences(prefName,Context.MODE_PRIVATE); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(AndroidJUnit4::class) | |
class OnDeviceTest { | |
@get:Rule val rule = ActivityTestRule(NoteListActivity::class.java) | |
@Test fun clickingOnTitle_shouldLaunchEditAction() { | |
onView(withId(R.id.button)).perform(click()) | |
intended(hasAction(equalTo("android.intent.action.EDIT"))) | |
} | |
} |
NewerOlder