Adding test module
This commit is contained in:
-26
@@ -1,26 +0,0 @@
|
||||
package com.ericampire.android.androidstudycase.room
|
||||
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.test.TestCoroutineDispatcher
|
||||
import kotlinx.coroutines.test.resetMain
|
||||
import kotlinx.coroutines.test.setMain
|
||||
import org.junit.rules.TestWatcher
|
||||
import org.junit.runner.Description
|
||||
|
||||
@ExperimentalCoroutinesApi
|
||||
class CoroutineTestRule(
|
||||
val testDispatcher: TestCoroutineDispatcher = TestCoroutineDispatcher()
|
||||
) : TestWatcher() {
|
||||
|
||||
override fun starting(description: Description?) {
|
||||
super.starting(description)
|
||||
Dispatchers.setMain(testDispatcher)
|
||||
}
|
||||
|
||||
override fun finished(description: Description?) {
|
||||
super.finished(description)
|
||||
Dispatchers.resetMain()
|
||||
testDispatcher.cleanupTestCoroutines()
|
||||
}
|
||||
}
|
||||
+13
-13
@@ -1,19 +1,19 @@
|
||||
buildscript {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
gradlePluginPortal()
|
||||
maven {
|
||||
url = uri("https://oss.sonatype.org/content/repositories/snapshots")
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
classpath(Libs.kotlin_gradle_plugin)
|
||||
classpath(Libs.gradle_plugin)
|
||||
classpath(Libs.hilt_gradle_plugin)
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
gradlePluginPortal()
|
||||
maven {
|
||||
url = uri("https://oss.sonatype.org/content/repositories/snapshots")
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
classpath(Libs.kotlin_gradle_plugin)
|
||||
classpath(Libs.gradle_plugin)
|
||||
classpath(Libs.hilt_gradle_plugin)
|
||||
}
|
||||
}
|
||||
|
||||
tasks.register("clean", Delete::class) {
|
||||
delete(rootProject.buildDir)
|
||||
delete(rootProject.buildDir)
|
||||
}
|
||||
@@ -63,6 +63,9 @@ object Libs {
|
||||
const val junit4 = "junit:junit:_"
|
||||
const val junit_jupiter_api = "org.junit.jupiter:junit-jupiter-api:_"
|
||||
const val junit_jupiter_engine = "org.junit.jupiter:junit-jupiter-engine:_"
|
||||
const val junit_jupiter_params = "org.junit.jupiter:junit-jupiter-params:_"
|
||||
|
||||
const val junit_vintage_engine = "org.junit.vintage:junit-vintage-engine:_"
|
||||
|
||||
// Todo: Put this in the version.properties file
|
||||
const val firebase_bom = "com.google.firebase:firebase-bom:28.1.0"
|
||||
|
||||
@@ -20,3 +20,4 @@ include(":util")
|
||||
include(":i18n")
|
||||
include(":data")
|
||||
include(":domain")
|
||||
//include(":test-shared")
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
/build
|
||||
@@ -0,0 +1,40 @@
|
||||
plugins {
|
||||
id("com.android.library")
|
||||
id("kotlin-android")
|
||||
kotlin("kapt")
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdk = Apps.compileSdk
|
||||
buildToolsVersion = Apps.buildToolsVersion
|
||||
|
||||
defaultConfig {
|
||||
minSdk = Apps.minSdk
|
||||
targetSdk = Apps.targetSdk
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
consumerProguardFiles("consumer-rules.pro")
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
isMinifyEnabled = false
|
||||
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
targetCompatibility = JavaVersion.VERSION_1_8
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(platform(Libs.kotlin_coroutine_bom))
|
||||
implementation(Libs.kotlin_coroutine_core)
|
||||
implementation(Libs.kotlin_coroutine_test)
|
||||
|
||||
implementation(Libs.junit_jupiter_api)
|
||||
implementation(Libs.junit_jupiter_engine)
|
||||
|
||||
testImplementation(Libs.mockk_core)
|
||||
}
|
||||
Vendored
+21
@@ -0,0 +1,21 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# You can control the set of applied configuration files using the
|
||||
# proguardFiles setting in build.gradle.kts.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest package="com.ericampire.android.androidstudycase.testshared">
|
||||
|
||||
</manifest>
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2019 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.ericampire.android.androidstudycase.testshared
|
||||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.test.TestCoroutineDispatcher
|
||||
import kotlinx.coroutines.test.TestCoroutineScope
|
||||
import kotlinx.coroutines.test.resetMain
|
||||
import kotlinx.coroutines.test.runBlockingTest
|
||||
import kotlinx.coroutines.test.setMain
|
||||
import org.junit.jupiter.api.AfterAll
|
||||
import org.junit.jupiter.api.BeforeAll
|
||||
import org.junit.jupiter.api.extension.AfterAllCallback
|
||||
import org.junit.jupiter.api.extension.BeforeAllCallback
|
||||
import org.junit.jupiter.api.extension.ExtensionContext
|
||||
|
||||
@ExperimentalCoroutinesApi
|
||||
class MainCoroutineExtension(
|
||||
val testDispatcher: TestCoroutineDispatcher = TestCoroutineDispatcher()
|
||||
) : BeforeAllCallback, AfterAllCallback {
|
||||
|
||||
override fun beforeAll(context: ExtensionContext?) {
|
||||
Dispatchers.setMain(testDispatcher)
|
||||
}
|
||||
|
||||
override fun afterAll(context: ExtensionContext?) {
|
||||
Dispatchers.resetMain()
|
||||
testDispatcher.cleanupTestCoroutines()
|
||||
}
|
||||
}
|
||||
|
||||
//fun MainCoroutineRule.runBlockingTest(block: suspend TestCoroutineScope.() -> Unit) =
|
||||
// this.testDispatcher.runBlockingTest {
|
||||
// block()
|
||||
// }
|
||||
//
|
||||
///**
|
||||
// * Creates a new [CoroutineScope] with the rule's testDispatcher
|
||||
// */
|
||||
//fun MainCoroutineRule.CoroutineScope(): CoroutineScope = CoroutineScope(testDispatcher)
|
||||
Reference in New Issue
Block a user