Skip to content

Instantly share code, notes, and snippets.

tomkoptel

Block or report user

Report or block tomkoptel

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@tomkoptel
tomkoptel / dashboar.json
Last active Mar 28, 2020
Sample Dashboard
View dashboar.json
{
"frameworks": [
{
"startDate": 1585388826446,
"endDate": 1585388826446,
"active": true,
"name": "Android"
},
{
"startDate": 1585388826446,
@tomkoptel
tomkoptel / AndroidTestOrchestrator.java
Created Apr 23, 2018
Extracted AndroidTestOrchestrator class from orchestrator-1.0.2-beta1.apk
View AndroidTestOrchestrator.java
package android.support.test.orchestrator;
import android.app.Instrumentation;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Build.VERSION;
import android.os.Bundle;
View CoolTask.kt
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.InputFile
import java.io.File
/**
* Make sure the task is open. Otherwise the plugin will fail with exception:
* org.gradle.api.GradleException: Could not generate a proxy class for class com.sample.coolplugin.CoolTask.
*/
open class CoolTask : DefaultTask() {
// Represents path to the instrumentation task that get generated for the tests
View CoolPlugin.kt
package com.sample.coolplugin
import org.gradle.api.DefaultTask
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.Task
class CoolPlugin : Plugin<Project> {
override fun apply(project: Project) {
validateAndroidPluginVersion3or31("Version of Android plugin should be >= 3.0")
@tomkoptel
tomkoptel / SugarVariantOutputDSL.kt
Last active Apr 22, 2018
Helper functions that introduce some sugar DSL around TestVariant and ApkVariantOutput instances.
View SugarVariantOutputDSL.kt
/**
* Yields all available variants of type [TestVariant].
*/
internal fun DomainObjectCollection<out BaseVariant>.forEachTestVariant(block: (TestVariant) -> Unit) {
all { variant ->
when (variant) {
is ApplicationVariant -> variant.testVariant?.let(block)
is TestVariant -> block(variant)
is LibraryVariant -> variant.testVariant?.let(block)
}
@tomkoptel
tomkoptel / ListVariantsAndroidPlugin.kt
Created Apr 22, 2018
A shortcut API to list Android Gradle variants.
View ListVariantsAndroidPlugin.kt
/**
* Returns the collection of Android variants on the basis of applied plugin. If the Android plugins are missing we
* are throwing build error.
*/
internal fun Project.getAndroidVariantsOrThrow(errorMessage: String): DomainObjectCollection<out BaseVariant> {
return when {
this.plugins.hasPlugin("com.android.application") -> {
val ext = project.extensions.findByType(AppExtension::class.java)
ext!!.applicationVariants
}
@tomkoptel
tomkoptel / ValidateAndroidPlugin.kt
Last active Apr 22, 2018
A shortcut API to validate Android Gradle plugin version validity.
View ValidateAndroidPlugin.kt
package com.sample.coolplugin
import org.gradle.api.Plugin
import org.gradle.api.Project
/**
* Verifies if the plugin supports Android Gradle plugin of version 3.0 or 3.1.
*/
internal fun Plugin<Project>.validateAndroidPluginVersion3or31(errorMessage: String) {
var gradlePluginVersion: String? = null
@tomkoptel
tomkoptel / AsyncIdlingResource.kt
Created Apr 14, 2018
Alternative way to make Espresso aware of the coroutines execution.
View AsyncIdlingResource.kt
import android.support.test.espresso.IdlingResource
import co.metalab.asyncawait.onIdleCoroutines
import co.metalab.asyncawait.onRunningCoroutine
class AsyncIdlingResource : IdlingResource {
private var areCoroutinesIdle = true
private var callback: IdlingResource.ResourceCallback? = null
override fun getName(): String = "AsyncIdlingResource"
@tomkoptel
tomkoptel / MainActivityTest.kt
Created Apr 14, 2018
Demonstrates usage of CoroutinesIdlingResourceRule in our UI test.
View MainActivityTest.kt
import android.support.test.espresso.Espresso.onView
import android.support.test.espresso.assertion.ViewAssertions.matches
import android.support.test.espresso.matcher.ViewMatchers.*
import android.support.test.runner.AndroidJUnit4
import android.view.View
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
// https://gist.github.com/tomkoptel/1101b2bb61f3daf251e3d627ee533b92
@tomkoptel
tomkoptel / CoroutinesIdlingResourceRule.kt
Last active Apr 18, 2018
JUnit 4 TestRule that replaces CoroutinesProvider implementation with Espresso aware one.
View CoroutinesIdlingResourceRule.kt
import android.support.test.espresso.IdlingRegistry
import android.support.test.espresso.IdlingResource
import kotlinx.coroutines.experimental.CoroutineScope
import kotlinx.coroutines.experimental.CoroutineStart
import kotlinx.coroutines.experimental.Job
import org.junit.rules.TestRule
import org.junit.runner.Description
import org.junit.runners.model.Statement
import kotlin.coroutines.experimental.CoroutineContext
You can’t perform that action at this time.