2
私はAndroidスタジオ2.0を使用しています。私はアンドロイドでもっと新鮮です。私のソースコードで 、Xml.newPullParser()JUnitテスト(テスト用ディレクトリ)で、私は入力して、それが、うまく に動作します。しかし、私はそれはnull.Whyが、それは私がそれと混同したのですか?たまたまやっ返しました。Xml.newPullParser()がAndroidテストでnullを返すのはなぜですか?
2番目の質問には、二つのディレクトリ(テストとandroidTest)がありますが、それらの間diffence何ですか?そして、私はどちらを使うべきでしょうか?
package com.ecust.ecusthelper.util.network.httpurlconnection;
import android.util.Xml;
import org.junit.Assert;
import org.junit.Test;
import org.xmlpull.v1.XmlPullParser;
public class XmlTest {
@Test
public void testXmlNonNull() {
XmlPullParser pull = Xml.newPullParser();
if (pull == null)
Assert.fail("Why here is null");
}
}
私のbuild.gradle
apply plugin: 'com.android.application'
apply plugin: 'me.tatarka.retrolambda'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.ecust.ecusthelper"
minSdkVersion 15
targetSdkVersion 23
versionCode 2
versionName '1.1'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
testOptions {
unitTests.returnDefaultValues = true
}
}
dependencies {
testCompile 'junit:junit:4.12'
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.4-beta2'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2'
testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2'
compile 'com.android.support:appcompat-v7:23.2.1'
....
}
あなたのsh 'build.gradle'の' junit'設定ですか?正確な 'testInstrumentationRunner'を指定していますか? – x0r
オハイオ州、私は 'testInstrumentationRunner'の使い方を知らない。ここに私の 'build.gradle'があります。私は' unitTests.returnDefaultValues = true'を使用しています。 – chenjj2048