Skip to content

Instantly share code, notes, and snippets.

@takaiwa
takaiwa / test
Last active October 5, 2020 07:05
Golang Live Templates
func Test$NAME$(t *testing.T) {
cases := map[string]struct {
input string
expected string
}{
"TestName Test1": {
input: "foo",
expected: "bar",
},
}
@takaiwa
takaiwa / MyTest.java
Last active June 28, 2016 05:24 — forked from romainpiel/MyTest.java
Source for https://medium.com/p/3f6f4179652e - "RecyclerView and espresso, a complicated story"
RecyclerViewInteraction.<Item>onRecyclerView(withId(R.id.recyclerview), 1)
.withItems(items)
.check(new ItemViewAssertion<Item>() {
@Override
public void check(Item item, View view, NoMatchingViewException e) {
matches(hasDescendant(withText(item.getDisplayName())))
.check(view, e);
}
});
@takaiwa
takaiwa / Item.java
Created May 17, 2016 05:51
RecyclerViewのリストの並びテストの補足用
public class Item {
String displayName;
public Item(String displayName) {
this.displayName = displayName;
}
public String getDisplayName() {
return displayName;
}
@takaiwa
takaiwa / MyViewAction.java
Created May 17, 2016 05:37
指定IDをクリックするカスタムMyViewAction
public static class MyViewAction {
public static ViewAction clickChildViewWithId(final int id) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return null;
}
@Override
@takaiwa
takaiwa / build.gradle
Created May 17, 2016 05:31
RecyclerviewをEspressoでテストするときのbuild.gradle
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile 'org.hamcrest:hamcrest-library:1.3'
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2'
androidTestCompile 'com.android.support:support-annotations:23.3.0'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support.test:rules:0.5'
androidTestCompile('com.android.support.test.espresso:espresso-contrib:2.2'){
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.android.support', module: 'recyclerview-v7'
@takaiwa
takaiwa / AutoHotkey.ahk
Last active March 31, 2016 01:03
Win + vを押すと、選択箇所をコピー→エディタを起動→貼り付けを行うAutoHotkeyのスクリプト
^!h:: ; Ctrl + Alt + h
Send ^c ; テキストをクリップボードにコピー
Run "C:\HogeEditor.exe"
Sleep 100
Clip0 = %ClipBoardAll%
ClipBoard = %ClipBoard% ; Convert to text
Send ^v ; For best compatibility: SendPlay
Sleep 50 ; Don't change clipboard while it is pasted! (Sleep > 0)
ClipBoard = %Clip0% ; Restore original ClipBoard
VarSetCapacity(Clip0, 0) ; Free memory
@takaiwa
takaiwa / TestData.java
Created December 19, 2015 08:27
Androidのテストケースでsrc/androidTest/resources/foo.jsonを読み込む
import android.test.ActivityInstrumentationTestCase2;
import android.util.Log;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
@takaiwa
takaiwa / ListVerifier.java
Last active December 16, 2015 01:07
型の異なるListをテストする時に便利なやつ
/**
* 型の異なるListの中身を検証しやすくするクラス
*
* Listを検証するにあたり、Listのサイズの検証、Listのどの位置でAssertionErrorが発生したかを
* このクラスで共通化し、abstractメソッドのverifyでListの中身の検証等を呼び出し元で行うもの
*
* [参考]
* http://dev.classmethod.jp/testing/unittesting/custom-assertion-using-junit/
* https://github.com/classmethod/cmtest/blob/master/cmtest-core/src/main/java/jp/classmethod/testing/verifier/ArrayVerifier.java
* Created by takaiwa.net on 2015/12/16.
@takaiwa
takaiwa / ConsumePurchase.java
Last active January 25, 2017 06:02
Google Play In-app Billing API v3:購入したものを消費するサンプル
final static String TAG = "hoge";
final static String base64EncodedPublicKey = "";
final static String PRODUCT_ID = "foo";
IabHelper mHelper;
/**
* テスト用
* 購入したものを消費する
*
* @param act
@takaiwa
takaiwa / OnActivityResultTest.java
Created September 24, 2015 09:18
onActivityResultのテスト
public class OnActivityResultTest extends InstrumentationTestCase {
public void test() throws Exception {
Instrumentation instrumentation = getInstrumentation();
Instrumentation.ActivityMonitor monitor = instrumentation.addMonitor(
TestTargetActivity.class.getName(), null, false);
// onActivityResultテスト対象のTestTargetActivityを起動
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);