Skip to content

Instantly share code, notes, and snippets.

package com.freshdigitable.sample
import android.content.Context
import android.os.Looper.getMainLooper
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.TextView
import androidx.lifecycle.Lifecycle
import androidx.test.core.app.ActivityScenario
import androidx.test.core.app.ApplicationProvider
/*
* Copyright (c) 2017. Matsuda, Akihit (akihito104)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2.2') {
exclude group:'com.android.support', module: 'appcompat-v7'
exclude group:'com.android.support', module: 'design'
exclude group:'com.android.support', module: 'recyclerview-v7'
exclude group:'com.android.support', module: 'support-v4'
}
@akihito104
akihito104 / HomeAndRelaunch.java
Last active July 2, 2016 06:23
android instrumentation test for home button interaction
Intent home = new Intent();
home.setAction(Intent.ACTION_MAIN);
home.addCategory(Intent.CATEGORY_HOME);
home.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Intent relaunch = new Intent(rule.getActivity(), rule.getActivity().getClass());
relaunch.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
InstrumentationRegistry.getTargetContext().startActivity(home);
Thread.sleep(500); // XXX
@akihito104
akihito104 / espresso_for_recyclerView.md
Last active September 17, 2017 04:09
Espresso for RecyclerView

custom matcher and assertion

  private Matcher<View> ofMyCustomView(Matcher<View> matcher) {
    return new BoundedMatcher<View, MyCustomView>(MyCustomView.class) {
      @Override
      protected boolean matchesSafely(MyCustomView item) {
        final Iterable<View> it = Iterables.filter(TreeIterables.breadthFirstViewTraversal(item),
            new Predicate<View>() {
              @Override