Skip to content

Commit

Permalink
All Widgets Test (partial) with some testability refactors. (getodk#1581
Browse files Browse the repository at this point in the history
)

Introduction of a simple dependency injection system through the DependencyProvider interface. In order to properly test all of the different code paths through each of the widgets, we need the ability to override some of the internal functionality. To do this, we need to strip this internal functionality out into an external, replaceable (i.e. mockable) class.

This refactor introduces a single use case of this: ActivityAvailability. FormEntryActivity now implements DependencyProvider<ActivityAvailability>, which lets the Widgets downstream know that it can provide an ActivityAvailability object when needed.

Normally this is what something like Dagger handles for us, but since we have a rather simple resource lifecycle (FormEntryActivity is always around when Widgets need access to these dependencies), this system does the same basic thing without requiring the mental/educational overhead of introducing Dagger.
  • Loading branch information
heyjamesknight authored and lognaturel committed Oct 31, 2017
1 parent 83c054f commit e495230
Show file tree
Hide file tree
Showing 21 changed files with 1,772 additions and 53 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ allprojects {
repositories {
jcenter()
maven { url = 'https://oss.sonatype.org/content/groups/public' }
maven {
url "https://maven.google.com"
}
}
}

Expand Down
21 changes: 16 additions & 5 deletions collect_app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,22 @@ dependencies {
testCompile group: 'org.robolectric', name: 'robolectric', version: '3.4'
testCompile group: 'org.robolectric', name: 'shadows-multidex', version: '3.3.2'

androidTestCompile group: 'org.mockito', name: 'mockito-android', version: '2.8.47'
androidTestCompile group: 'com.android.support', name: 'support-annotations', version: '25.3.1'
androidTestCompile group: 'com.android.support.test', name: 'runner', version: '0.5'
androidTestCompile group: 'com.android.support.test', name: 'rules', version: '0.5'
androidTestCompile group: 'com.squareup.okhttp3', name: 'mockwebserver', version: '3.2.0'
androidTestCompile group: 'org.mockito', name: 'mockito-android', version: '2.11.0'
androidTestCompile(group: 'com.android.support.test', name: 'runner', version: '1.0.1') {
exclude group: 'com.android.support', module: 'support-annotations'
}

androidTestCompile(group: 'com.android.support.test.espresso', name: 'espresso-core', version: '3.0.1') {
exclude group: 'com.android.support', module: 'support-annotations'
exclude group: 'com.google.code.findbugs', module: 'jsr305'
}

androidTestCompile(group: 'com.android.support.test.espresso', name: 'espresso-intents', version: '3.0.1') {
exclude group: 'com.android.support', module: 'support-annotations'
exclude group: 'com.google.code.findbugs', module: 'jsr305'
}

androidTestCompile group: 'com.squareup.okhttp3', name: 'mockwebserver', version: '3.9.0'
}

// Must be at bottom to prevent dependency collisions
Expand Down
855 changes: 855 additions & 0 deletions collect_app/src/androidTest/assets/all_widgets.xml

Large diffs are not rendered by default.

Loading

0 comments on commit e495230

Please sign in to comment.