我使用Android studio verison 2.3.1,我想使用espresso进行测试,但遇到问题如下图Test running failed
我的测试java文件
package com.view.asim;
import android.support.test.filters.LargeTest;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import com.view.asim.activity.MainActivity;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
/**
* Created by OF on 2017/4/28.
*/
@RunWith(AndroidJUnit4.class)
@LargeTest
public class MakeSureLogin {
private String mStringToBetyped;
@Rule
public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(
MainActivity.class);
@Before
public void initValidString() {
// Specify a valid string.
}
@Test
public void changeText_sameActivity() {
// Check that the text was changed.
onView(withId(R.id.account_txt)).perform().check(matches(withText(mStringToBetyped)));
}
}
我知道stackoverflow中有类似的问题已经被问过,而且有些人也有问题,但这些解决方案(如this)无法解决我的问题。 有人说可以specific instrumentation runner,但Android工作室版本2.3中没有动作。我认为它可能与multildex相关,真的希望有些人可以帮助我,任何建议都会非常感激。这是我的build.gralde档案
defaultConfig {
//...
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
//...
}
productFlavors {
zixuntong{
applicationIdSuffix ".mixuntong"
manifestPlaceholders = otherHolderMap
manifestPlaceholders.put("PACKAGE_NAME",ASIM_PKG_NAME+applicationIdSuffix)
buildConfigField "boolean", "isAddShare", "false"
buildConfigField "boolean", "isZXT", "true"
}
}
//.....
androidTestZixuntongCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
// compile 'com.android.support:support-annotations:22.2.0'
androidTestZixuntongCompile 'com.android.support.test:runner:0.5'
testCompile 'junit:junit:4.12'
androidTestZixuntongCompile('com.android.support:multidex-instrumentation:1.0.1') {
exclude group: 'com.android.support', module: 'multidex'
}
configurations.all {
resolutionStrategy.force 'com.android.support:support-annotations:23.1.0'
}
//...
//had trying follow script,but still doesn't work androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',
{ 排除组:'com.android.support',模块:'support-annotations' })
答案 0 :(得分:0)
我发现在将Android Studio从2.3.1升级到2.3.2之后我已修复此问题。