Skip to content

Instantly share code, notes, and snippets.

View phellipealexandre's full-sized avatar
🎯
Focusing

Phellipe Silva phellipealexandre

🎯
Focusing
View GitHub Profile
@phellipealexandre
phellipealexandre / robolectric4Example.kt
Last active August 20, 2018 12:43
Robolectric instrumentation test in Kotlin
@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")))
}
}
@phellipealexandre
phellipealexandre / instrumetationExample.java
Last active August 20, 2018 12:45
Example of instrumentation test in Android
@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);
@phellipealexandre
phellipealexandre / espresso.java
Created August 19, 2018 15:06
Espresso test example
@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()));
}
@phellipealexandre
phellipealexandre / uiautomator.java
Last active October 29, 2018 10:27
Snippet of UI Automator Android test
// 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();
class CarTest {
private lateinit var car: Car
@Before
fun setUp() {
car = Car()
}
@Test
import androidx.test.core.app.ApplicationProvider
@RunWith(AndroidJUnit4::class)
class DatabaseTest {
private lateinit var database: MainDatabase
@Before
fun setUp() {
val context = ApplicationProvider.getApplicationContext<Context>()
@RunWith(AndroidJUnit4::class)
class ChangeTextBehaviorTest {
@get:Rule
var activityRule: ActivityTestRule<MainActivity> = ActivityTestRule(MainActivity::class.java)
@Test
fun changeText_sameActivity() {
onView(withId(R.id.editTextUserInput)).perform(typeText("Espresso"), closeSoftKeyboard())
adb shell settings put global window_animation_scale 0
adb shell settings put global transition_animation_scale 0
adb shell settings put global animator_duration_scale 0
make disable-animations
lint:
./gradlew lintCheckErrors --info
run-unit-tests:
./gradlew test
run-instrumented-tests: clear-app-data disable-animations
./gradlew connectedAndroidTest
run-all-tests: run-unit-tests build-install-app run-instrumented-tests