Skip to content
This repository was archived by the owner on Dec 11, 2024. It is now read-only.

Commit 717673b

Browse files
committed
Creating Starter Code for Advanced Android codelab
1 parent 043c38c commit 717673b

File tree

102 files changed

+1109
-4921
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+1109
-4921
lines changed

README.md

+49-11
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,64 @@
1-
# Android Testing Codelab
1+
TO-DO Notes - Code for 5.1-5.3 Testing Codelab
2+
============================================================================
23

3-
This folder contains the source code for the Android testing codelab. It gives an introduction into testing on Android, including unit tests and UI tests.
4-
https://codelabs.developers.google.com/codelabs/android-testing/
4+
Code for the Advanced Android Kotlin Testing Codelab 5.1-5.3
55

6-
### License
6+
Introduction
7+
------------
78

9+
TO-DO Notes is an app where you to write down tasks to complete. The app displays them in a list.
10+
You can then mark them as completed or not, filter them and delete them.
11+
12+
![App main screen, screenshot](screenshot.png)
13+
14+
This codelab has four branches, representing different code states:
15+
16+
* [starter_code](https://github.com/googlecodelabs/android-testing/tree/starter_code)
17+
* [end_codelab_1](https://github.com/googlecodelabs/android-testing/tree/end_codelab_1)
18+
* [end_codelab_2](https://github.com/googlecodelabs/android-testing/tree/end_codelab_2)
19+
* [end_codelab_3](https://github.com/googlecodelabs/android-testing/tree/end_codelab_3)
20+
21+
The codelabs in this series are:
22+
* [Testing Basics](https://codelabs.developers.google.com/codelabs/advanced-android-kotlin-training-testing-basics)
23+
* [Introduction to Test Doubles and Dependency Injection](https://codelabs.developers.google.com/codelabs/advanced-android-kotlin-training-testing-test-doubles)
24+
* [Survey of Testing Topics](https://codelabs.developers.google.com/codelabs/advanced-android-kotlin-training-testing-survey)
25+
26+
27+
Pre-requisites
28+
--------------
29+
30+
You should be familiar with:
31+
32+
* The Kotlin programming language, including [Kotlin coroutines](https://developer.android.com/kotlin/coroutines) and their interaction with [Android Jetpack components](https://developer.android.com/topic/libraries/architecture/coroutines).
33+
* The following core Android Jetpack libraries: [ViewModel](https://developer.android.com/topic/libraries/architecture/viewmodel),
34+
[LiveData](https://developer.android.com/topic/libraries/architecture/livedata),
35+
[Navigation Component](https://developer.android.com/guide/navigation) and
36+
[Data Binding](https://developer.android.com/topic/libraries/data-binding).
37+
* Application architecture, following the pattern from the [Guide to app architecture](https://developer.android.com/jetpack/docs/guide) and [Android Fundamentals codelabs](https://developer.android.com/courses/kotlin-android-fundamentals/toc).
38+
39+
40+
Getting Started
41+
---------------
42+
43+
1. Download and run the app.
44+
2. Check out one of the codelabs mentioned above.
45+
46+
License
47+
-------
848

9-
```
1049
Copyright 2019 Google, Inc.
1150

1251
Licensed to the Apache Software Foundation (ASF) under one or more contributor
13-
license agreements. See the NOTICE file distributed with this work for
14-
additional information regarding copyright ownership. The ASF licenses this
52+
license agreements. See the NOTICE file distributed with this work for
53+
additional information regarding copyright ownership. The ASF licenses this
1554
file to you under the Apache License, Version 2.0 (the "License"); you may not
16-
use this file except in compliance with the License. You may obtain a copy of
55+
use this file except in compliance with the License. You may obtain a copy of
1756
the License at
1857

19-
http://www.apache.org/licenses/LICENSE-2.0
58+
http://www.apache.org/licenses/LICENSE-2.0
2059

2160
Unless required by applicable law or agreed to in writing, software
2261
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
23-
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
62+
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
2463
License for the specific language governing permissions and limitations under
2564
the License.
26-
```

app/build.gradle

+7-112
Original file line numberDiff line numberDiff line change
@@ -3,81 +3,21 @@ apply plugin: 'kotlin-android'
33
apply plugin: 'kotlin-kapt'
44
apply plugin: "androidx.navigation.safeargs.kotlin"
55

6-
repositories {
7-
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
8-
}
9-
106
android {
117
compileSdkVersion rootProject.compileSdkVersion
128

139
defaultConfig {
14-
applicationId "com.example.android.architecture.blueprints.todomvvmlivekotlin"
10+
applicationId "com.example.android.architecture.blueprints.reactive"
1511
minSdkVersion rootProject.minSdkVersion
1612
targetSdkVersion rootProject.targetSdkVersion
1713
versionCode 1
1814
versionName "1.0"
19-
20-
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
15+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
2116
}
22-
23-
android {
24-
sourceSets {
25-
String sharedTestDir = 'src/sharedTest/java'
26-
test {
27-
java.srcDir sharedTestDir
28-
}
29-
androidTest {
30-
java.srcDir sharedTestDir
31-
}
32-
}
33-
}
34-
3517
buildTypes {
36-
debug {
37-
minifyEnabled false
38-
testCoverageEnabled true
39-
useProguard false
40-
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
41-
testProguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguardTest-rules.pro'
42-
}
43-
4418
release {
45-
minifyEnabled true
46-
useProguard true
47-
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
48-
testProguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguardTest-rules.pro'
49-
}
50-
}
51-
52-
flavorDimensions "default"
53-
54-
// If you need to add more flavors, consider using flavor dimensions.
55-
productFlavors {
56-
mock {
57-
dimension "default"
58-
applicationIdSuffix = ".mock"
59-
}
60-
prod {
61-
dimension "default"
62-
}
63-
}
64-
65-
// Remove mockRelease as it's not needed.
66-
android.variantFilter { variant ->
67-
if (variant.buildType.name == 'release'
68-
&& variant.getFlavors().get(0).name == 'mock') {
69-
variant.setIgnore(true)
70-
}
71-
}
72-
73-
// Always show the result of every unit test, even if it passes.
74-
testOptions.unitTests {
75-
includeAndroidResources = true
76-
77-
all {
78-
testLogging {
79-
events 'passed', 'skipped', 'failed', 'standardOut', 'standardError'
80-
}
19+
minifyEnabled false
20+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
8121
}
8222
}
8323

@@ -87,10 +27,6 @@ android {
8727
}
8828
}
8929

90-
/*
91-
Dependency versions are defined in the top level build.gradle file. This helps keeping track of
92-
all versions in a single place. This improves readability and helps managing project complexity.
93-
*/
9430
dependencies {
9531

9632
// App dependencies
@@ -102,8 +38,6 @@ dependencies {
10238
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion"
10339
implementation "com.jakewharton.timber:timber:$timberVersion"
10440
implementation "androidx.legacy:legacy-support-v4:$androidXLegacySupport"
105-
implementation "androidx.test.espresso:espresso-idling-resource:$espressoVersion"
106-
implementation "com.google.guava:guava:$guavaVersion"
10741
implementation "androidx.room:room-runtime:$roomVersion"
10842
kapt "androidx.room:room-compiler:$roomVersion"
10943

@@ -114,57 +48,18 @@ dependencies {
11448
implementation "androidx.lifecycle:lifecycle-extensions:$archLifecycleVersion"
11549
kapt "androidx.lifecycle:lifecycle-compiler:$archLifecycleVersion"
11650
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$archLifecycleVersion"
51+
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$archLifecycleVersion"
11752
implementation "androidx.navigation:navigation-fragment-ktx:$navigationVersion"
11853
implementation "androidx.navigation:navigation-ui-ktx:$navigationVersion"
11954

12055
// Dependencies for local unit tests
12156
testImplementation "junit:junit:$junitVersion"
122-
testImplementation "org.mockito:mockito-core:$mockitoVersion"
123-
testImplementation "org.hamcrest:hamcrest-all:$hamcrestVersion"
124-
testImplementation "androidx.arch.core:core-testing:$archTestingVersion"
125-
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion"
126-
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutinesVersion"
127-
testImplementation "org.robolectric:robolectric:$robolectricVersion"
128-
testImplementation "androidx.test.espresso:espresso-core:$espressoVersion"
129-
testImplementation "androidx.test.espresso:espresso-contrib:$espressoVersion"
130-
testImplementation "androidx.test.espresso:espresso-intents:$espressoVersion"
131-
testImplementation "com.google.truth:truth:$truthVersion"
132-
133-
// Dependencies for Android unit tests
134-
androidTestImplementation "junit:junit:$junitVersion"
135-
androidTestImplementation "org.mockito:mockito-core:$mockitoVersion"
136-
androidTestImplementation "com.linkedin.dexmaker:dexmaker-mockito:$dexMakerVersion"
137-
androidTestImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutinesVersion"
138-
139-
// AndroidX Test - JVM testing
140-
testImplementation "androidx.test:core-ktx:$androidXTestCoreVersion"
141-
testImplementation "androidx.test.ext:junit-ktx:$androidXTestExtKotlinRunnerVersion"
142-
testImplementation "androidx.test:rules:$androidXTestRulesVersion"
143-
// Once https://issuetracker.google.com/127986458 is fixed this can be testImplementation
144-
implementation "androidx.fragment:fragment-testing:$fragmentVersion"
145-
implementation "androidx.test:core:$androidXTestCoreVersion"
146-
implementation "androidx.fragment:fragment:$fragmentVersion"
14757

14858
// AndroidX Test - Instrumented testing
149-
androidTestImplementation "androidx.test:core-ktx:$androidXTestCoreVersion"
150-
androidTestImplementation "androidx.test.ext:junit-ktx:$androidXTestExtKotlinRunnerVersion"
151-
androidTestImplementation "androidx.test:rules:$androidXTestRulesVersion"
152-
androidTestImplementation "androidx.room:room-testing:$roomVersion"
153-
androidTestImplementation "androidx.arch.core:core-testing:$archTestingVersion"
59+
androidTestImplementation "androidx.test.ext:junit:$androidXTestExtKotlinRunnerVersion"
15460
androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVersion"
155-
androidTestImplementation "androidx.test.espresso:espresso-contrib:$espressoVersion"
156-
androidTestImplementation "androidx.test.espresso:espresso-intents:$espressoVersion"
157-
androidTestImplementation "androidx.test.espresso.idling:idling-concurrent:$espressoVersion"
158-
androidTestImplementation "org.robolectric:annotations:$robolectricVersion"
159-
implementation "androidx.test.espresso:espresso-idling-resource:$espressoVersion"
160-
161-
// Resolve conflicts between main and test APK:
162-
androidTestImplementation "androidx.annotation:annotation:$androidXAnnotations"
163-
androidTestImplementation "androidx.legacy:legacy-support-v4:$androidXLegacySupport"
164-
androidTestImplementation "androidx.recyclerview:recyclerview:$recyclerViewVersion"
165-
androidTestImplementation "androidx.appcompat:appcompat:$appCompatVersion"
166-
androidTestImplementation "com.google.android.material:material:$materialVersion"
16761

16862
// Kotlin
16963
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
64+
implementation "androidx.fragment:fragment-ktx:$fragmentKtxVersion"
17065
}

app/proguard-rules.pro

+21-36
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,21 @@
1-
-dontoptimize
2-
3-
# Some methods are only called from tests, so make sure the shrinker keeps them.
4-
-keep class com.example.android.architecture.blueprints.** { *; }
5-
6-
-keep class androidx.drawerlayout.widget.DrawerLayout { *; }
7-
-keep class androidx.test.espresso.**
8-
# keep the class and specified members from being removed or renamed
9-
-keep class androidx.test.espresso.IdlingRegistry { *; }
10-
-keep class androidx.test.espresso.IdlingResource { *; }
11-
12-
-keep class com.google.common.base.Preconditions { *; }
13-
14-
-keep class androidx.room.RoomDataBase { *; }
15-
-keep class androidx.room.Room { *; }
16-
-keep class android.arch.** { *; }
17-
18-
# For Guava:
19-
-dontwarn javax.annotation.**
20-
-dontwarn javax.inject.**
21-
-dontwarn sun.misc.Unsafe
22-
23-
# Proguard rules that are applied to your test apk/code.
24-
-ignorewarnings
25-
26-
-keepattributes *Annotation*
27-
28-
-dontnote junit.framework.**
29-
-dontnote junit.runner.**
30-
31-
-dontwarn androidx.test.**
32-
-dontwarn org.junit.**
33-
-dontwarn org.hamcrest.**
34-
-dontwarn com.squareup.javawriter.JavaWriter
35-
# Uncomment this if you use Mockito
36-
-dontwarn org.mockito.**
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile

app/proguardTest-rules.pro

-20
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.example.android.architecture.blueprints.todoapp
2+
3+
import androidx.test.platform.app.InstrumentationRegistry
4+
import androidx.test.ext.junit.runners.AndroidJUnit4
5+
6+
import org.junit.Test
7+
import org.junit.runner.RunWith
8+
9+
import org.junit.Assert.*
10+
11+
/**
12+
* Instrumented test, which will execute on an Android device.
13+
*
14+
* See [testing documentation](http://d.android.com/tools/testing).
15+
*/
16+
@RunWith(AndroidJUnit4::class)
17+
class ExampleInstrumentedTest {
18+
@Test
19+
fun useAppContext() {
20+
// Context of the app under test.
21+
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22+
assertEquals("com.example.android.architecture.blueprints.reactive",
23+
appContext.packageName)
24+
}
25+
}

0 commit comments

Comments
 (0)