Skip to content

Instantly share code, notes, and snippets.

@wakwak3125
Created January 14, 2016 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wakwak3125/d40392ac13c330b060e8 to your computer and use it in GitHub Desktop.
Save wakwak3125/d40392ac13c330b060e8 to your computer and use it in GitHub Desktop.
LeakCanary + Robolectricでテストするときの注意 ref: http://qiita.com/wakwak3125/items/1cae809dbfa6e68b5890
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.wakwak.leakcanarytest"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
beta {
minifyEnabled false
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
testCompile 'org.robolectric:robolectric:3.0'
compile 'com.android.support:appcompat-v7:23.1.1'
betaCompile 'com.squareup.leakcanary:leakcanary-android:1.4-beta1'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta1'
}
@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 21, packageName = "com.wakwak.leakcanarytest")
public class ExampleUnitTest {
@Test
public void addition_isCorrect() throws Exception {
assertEquals(4, 2 + 2);
}
}
betaCompile 'com.squareup.leakcanary:leakcanary-android:1.4-beta1'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta1'
./gradlew testReleaseUnitTest
:app:preBuild UP-TO-DATE
:app:preReleaseBuild UP-TO-DATE
:app:checkReleaseManifest
:app:preBetaBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72311Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42311Library UP-TO-DATE
:app:prepareComSquareupLeakcanaryLeakcanaryAndroidNoOp14Beta1Library UP-TO-DATE
:app:prepareReleaseDependencies
:app:compileReleaseAidl UP-TO-DATE
:app:compileReleaseRenderscript UP-TO-DATE
:app:generateReleaseBuildConfig UP-TO-DATE
:app:generateReleaseAssets UP-TO-DATE
:app:mergeReleaseAssets UP-TO-DATE
:app:generateReleaseResValues UP-TO-DATE
:app:generateReleaseResources UP-TO-DATE
:app:mergeReleaseResources UP-TO-DATE
:app:processReleaseManifest
:app:processReleaseResources
:app:generateReleaseSources
:app:processReleaseJavaRes UP-TO-DATE
:app:compileReleaseJavaWithJavac
:app:preReleaseUnitTestBuild UP-TO-DATE
:app:prepareReleaseUnitTestDependencies
:app:processReleaseUnitTestJavaRes UP-TO-DATE
:app:compileReleaseUnitTestJavaWithJavac
:app:compileReleaseUnitTestSources
:app:mockableAndroidJar UP-TO-DATE
:app:assembleReleaseUnitTest
:app:testReleaseUnitTest
BUILD SUCCESSFUL
Total time: 13.652 secs
./gradlew testBetaUnitTest
:app:preBuild UP-TO-DATE
:app:preBetaBuild UP-TO-DATE
:app:checkBetaManifest
:app:preDebugBuild UP-TO-DATE
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72311Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42311Library UP-TO-DATE
:app:prepareComSquareupLeakcanaryLeakcanaryAndroid14Beta1Library UP-TO-DATE
:app:prepareBetaDependencies
:app:compileBetaAidl UP-TO-DATE
:app:compileBetaRenderscript UP-TO-DATE
:app:generateBetaBuildConfig UP-TO-DATE
:app:generateBetaAssets UP-TO-DATE
:app:mergeBetaAssets UP-TO-DATE
:app:generateBetaResValues UP-TO-DATE
:app:generateBetaResources UP-TO-DATE
:app:mergeBetaResources UP-TO-DATE
:app:processBetaManifest UP-TO-DATE
:app:processBetaResources UP-TO-DATE
:app:generateBetaSources UP-TO-DATE
:app:processBetaJavaRes UP-TO-DATE
:app:compileBetaJavaWithJavac UP-TO-DATE
:app:preBetaUnitTestBuild UP-TO-DATE
:app:prepareBetaUnitTestDependencies
:app:processBetaUnitTestJavaRes UP-TO-DATE
:app:compileBetaUnitTestJavaWithJavac UP-TO-DATE
:app:compileBetaUnitTestSources UP-TO-DATE
:app:mockableAndroidJar UP-TO-DATE
:app:assembleBetaUnitTest UP-TO-DATE
:app:testBetaUnitTest
com.wakwak.leakcanarytest.ExampleUnitTest > addition_isCorrect FAILED
java.lang.RuntimeException
Caused by: java.lang.NullPointerException
1 test completed, 1 failed
:app:testBetaUnitTest FAILED
FAILURE: Build failed with an exception.
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
try {
LeakCanary.install(this);
} catch (Exception ignore) {
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment