编辑:更新了描述和错误消息并添加了一些图像.还是有这个问题.
运行espresso测试时,我发生了很多次奇怪的错误.经过几次成功的测试运行后,测试开始失败并出现以下异常:
06-23 13:04:48.438 info TestRunner failed: WhenNavigatingToReportsThenCorrectViewShouldBeShown(com.myapp.ui.views.MainActivityTest)
06-23 13:04:48.439 info TestRunner ----- begin exception -----
06-23 13:04:48.441 info TestRunner android.support.test.espresso.NoActivityResumedException: No activities in stage RESUMED. Did you forget to launch the activity. (test.getActivity() or similar)?
06-23 13:04:48.441 info TestRunner at dalvik.system.VMStack.getThreadStackTrace(Native Method)
06-23 13:04:48.441 info TestRunner at java.lang.Thread.getStackTrace(Thread.java:580)
06-23 13:04:48.441 info TestRunner at android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:82)
06-23 13:04:48.441 info TestRunner at android.support.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:53)
06-23 13:04:48.441 info TestRunner at android.support.test.espresso.ViewInteraction.runSynchronouslyOnUiThread(ViewInteraction.java:184)
06-23 13:04:48.441 info TestRunner at android.support.test.espresso.ViewInteraction.doPerform(ViewInteraction.java:115)
06-23 13:04:48.441 info TestRunner at android.support.test.espresso.ViewInteraction.perform(ViewInteraction.java:87)
06-23 …
Run Code Online (Sandbox Code Playgroud) 我有一个产品有多种产品口味,如:
buildTypes {
debug {
}
release {
}
}
productFlavors {
flavor1 {
buildConfigField "String" "country" "se"
buildConfigField "String" "language" "sv-SE"
buildConfigField "String" "appName" "Flavor1"
}
flavor2 {
buildConfigField "String" "country" "se"
buildConfigField "String" "language" "sv-SE"
buildConfigField "String" "appName" "Flavor2"
}
flavor3 {
buildConfigField "String" "country" "se"
buildConfigField "String" "language" "sv-SE"
buildConfigField "String" "appName" "Flavor3"
}
flavor4 {
buildConfigField "String" "country" "se"
buildConfigField "String" "language" "sv-SE"
buildConfigField "String" "appName" "Flavor4"
}
flavor5 {
buildConfigField "String" "country" "se"
buildConfigField "String" …
Run Code Online (Sandbox Code Playgroud) 我今天做了一个简单的测试:
@RunWith(AndroidJUnit4.class)
@LargeTest
public class WhenNavigatingToUsersView {
@Rule
public ActivityTestRule<MainActivity> mActivityRule =
new ActivityTestRule(MainActivity.class);
private MainActivity mainActivity;
@Before
public void setActivity() {
mainActivity = mActivityRule.getActivity();
onView(allOf(withId(R.id.icon), hasSibling(withText(R.string.users)))).perform(click());
}
@Test
public void thenCorrectViewTitleShouldBeShown() {
onView(withText("This is the Users Activity.")).check(matches(isDisplayed()));
}
@Test
public void thenCorrectUserShouldBeShown() {
onView(withText("Donald Duck (1331)")).check(matches(isDisplayed()));
}
}
Run Code Online (Sandbox Code Playgroud)
但是对于每个setActivity
运行的测试方法,如果你有10-15个方法,最后将是耗时的(如果你也有很多视图).
@BeforeClass
似乎不起作用,因为它必须是静态的,因此也强迫它ActivityTestRule
是静态的.
那么有没有其他方法可以做到这一点?而不是在同一个测试方法中有多个断言?
我有一个popupmenu.Uix截图提供.现在,我想通过单击它们来验证列表中的某些项目并验证发生了什么.
但无论我做什么,我似乎都无法在弹出菜单中选择项目.菜单没有ID,我认为不可能设置菜单的ID.
我尝试过不同的东西,比如:
onView(nthChildOf(anyOf(withId(android.R.id.title)), 1)).perform(click());
onView(withText("5 sekunder")).perform(click());
Run Code Online (Sandbox Code Playgroud)
但没有任何作用.如何单击弹出菜单中的项目?在这里,您可以找到带有弹出菜单视图层的UIX文件.
编辑:
更明显的是,当您单击操作栏右角的点以展开子菜单时.在我的情况下,子菜单总是由三个项目组成.我最接近解决方案的是:
onData(anything()).atPosition(2).perform(click());
Run Code Online (Sandbox Code Playgroud)
但大多数情况下它会打开第一个项目,而不是第二个项目中的项目
No activities in stage RESUMED. Did you forget to launch the activity. (test.getActivity() or similar)?
Run Code Online (Sandbox Code Playgroud)
日志可以在这里找到.在日志中,您可以看到它实际上点击了错误的项目,它点击"点击菜单:菜单1".
在构建我的android应用时,我尝试根据调试或发布模式提供不同的基本名称。但是它从来没有达到我的期望,我也想不出如何解决它。
我的gradle中有一个android部分,看起来像这样:
def applicationVersionCode() {
return 14;
}
def applicationVersionName() {
return "1.5";
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
useLibrary 'org.apache.http.legacy' // fix for https://github.com/loopj/android-async-http/issues/830
}
defaultConfig {
applicationId defaultApplicationId
versionCode applicationVersionCode()
versionName applicationVersionName()
project.ext.set("archivesBaseName", "AppName-" + applicationVersionName() + applicationVersionCode())
minSdkVersion 16
targetSdkVersion 17
}
buildTypes {
debug {
minifyEnabled false
versionNameSuffix "." + applicationVersionCode() + "-SNAPSHOT"
applicationIdSuffix ".debug"
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
Run Code Online (Sandbox Code Playgroud)
在构建调试模式时,应用会获得名称:
AppName-1.14-debug.apk
Run Code Online (Sandbox Code Playgroud)
当我添加:
project.ext.set("archivesBaseName", "AppName-" + applicationVersionName() + applicationVersionCode()) …
Run Code Online (Sandbox Code Playgroud) 我的gradle脚本中有一个上传任务:
uploadArchives {
repositories {
mavenDeployer {
repository(url: "${nexusUrl}/content/repositories/apps-releases") {
authentication(userName: nexusUsername, password: nexusPassword)
}
snapshotRepository(url: "${nexusUrl}/content/repositories/apps-snapshots") {
authentication(userName: nexusUsername, password: nexusPassword)
}
pom.groupId = "$defaultApplicationId"
pom.artifactId = 'MyApp'
pom.version = applicationVersionName()
}
}
}
Run Code Online (Sandbox Code Playgroud)
从teamcity运行这个:
clean assembleDebug testDebugUnitTest crashlyticsUploadDistributionDebug uploadArchives
Run Code Online (Sandbox Code Playgroud)
在构建调试版本之后,似乎uploadArchives也正在构建一个发行版本.因此,当构建完成时,我将调试和发布apk作为生成的构造中的人工制品.但如果我删除uploadArchives它只生成调试apk.
反正有没有阻止这个?这不是什么大问题,但只建立我指定的版本会很好; 即uploadDebugArchives和uploadReleaseArchives会很好......
我的声纳配置看起来像这样:
sonar.jdbc.username=sonar
sonar.jdbc.password=sonar
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncod$
sonar.jdbc.driverClassName=com.mysql.jdbc.Driver
sonar.jdbc.validationQuery=select 1
sonar.web.host=127.0.0.1
sonar.web.context=/sonar
sonar.web.port=9000
Run Code Online (Sandbox Code Playgroud)
从我的gradle脚本运行时,它看起来像这样:
sonarProperties {
property "sonar.projectKey", "sonar-example"
property "sonar.projectName", "sonar example"
property "sonar.projectVersion", "1.0"
property "sonar.sources", "src/main/java"
property "sonar.binaries", "build"
property "sonar.test", "src/test/java"
property "sonar.language", "java"
property "sonar.profile", "Android Lint"
property "sonar.android.lint.report", "lint-report.xml"
property "sonar.dynamicAnalysis", "reuseReports"
property "sonar.sourceEncoding", "UTF-8"
property "sonar.junit.reportsPath", "build/outputs/reports/coverage/debug"
property "sonar.cobertura.reportPath", "build/outputs/reports/coverage/debug/cobertura.xml"
property "sonar.java.coveragePlugin", "cobertura"
property "sonar.host.url", "http://localhost:9000/sonar"
property "sonar.jdbc.username", "sonar"
property "sonar.jdbc.password", "sonar"
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
pepes-MacBook-Pro-4:android-robolectric-test pepe$ ./gradlew sonarRunner
:app:sonarRunner
SonarQube Runner 2.3
Java 1.7.0_75 Oracle Corporation …
Run Code Online (Sandbox Code Playgroud)