Skip to content

Instantly share code, notes, and snippets.

@ShinichiroFunatsu
Created September 4, 2019 16:23
Show Gist options
  • Save ShinichiroFunatsu/b909319cfa83a910b9979ba20f353025 to your computer and use it in GitHub Desktop.
Save ShinichiroFunatsu/b909319cfa83a910b9979ba20f353025 to your computer and use it in GitHub Desktop.
[WIP] Bridge for Using DescribeSpec(KotlinTest) in Java
import io.kotlintest.runner.junit4.KotlinTestRunner
import io.kotlintest.specs.AbstractDescribeSpec
import org.junit.runner.RunWith
import java.util.function.Consumer
import java.util.function.Function
@RunWith(KotlinTestRunner::class)
abstract class DescribeSpec4JKt : AbstractDescribeSpec() {
var currentScope: DescribeScope? = null
fun describe2(name: String, test: Runnable) {
describe(name) {
currentScope = this
test.run()
}
}
fun asyncIt(name: String, test: Runnable) {
// FIXME
it2(name, test)
}
private suspend fun it2(name: String, test: Runnable) {
currentScope?.it(name) {
test.run()
}
}
}
@ShinichiroFunatsu
Copy link
Author

https://stackoverflow.com/questions/52869672/call-kotlin-suspend-function-in-java-class

but can run with org.jetbrains.kotlinx:kotlinx-coroutines-jdk8

@ShinichiroFunatsu
Copy link
Author

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "app.sfunatsu.specforandroidjava"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    testOptions {
        unitTests.all {
            useJUnitPlatform()
        }
    }
    compileOptions {
        sourceCompatibility = '1.8'
        targetCompatibility = '1.8'
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    testImplementation 'io.kotlintest:kotlintest-runner-junit4:3.3.2'
    // for resolve error
    testImplementation 'org.slf4j:slf4j-log4j12:1.7.21'
    testImplementation 'com.google.truth:truth:1.0'

    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment