Spek: Android studio 3.0

Created on 7 Nov 2017  路  6Comments  路  Source: spekframework/spek

Hello! After the renovation of the studio, my tests stopped working. I saw the topic https://github.com/spekframework/spek/issues/256 But that did not solve my problem. Can you help me? I even made a new project with the settings as in the topic , but it also does not work.

org.junit.platform.commons.util.PreconditionViolationException: Could not load class with name: com.livechat.android.ui.activity.login.LoginPresenterTest at org.junit.platform.engine.discovery.ClassSelector.lambda$getJavaClass$0(ClassSelector.java:71) at java.util.Optional.orElseThrow(Optional.java:290) at org.junit.platform.engine.discovery.ClassSelector.getJavaClass(ClassSelector.java:70) at org.jetbrains.spek.engine.SpekTestEngine.resolveSpecs(SpekTestEngine.kt:79) at org.jetbrains.spek.engine.SpekTestEngine.discover(SpekTestEngine.kt:50) at org.junit.platform.launcher.core.DefaultLauncher.discoverEngineRoot(DefaultLauncher.java:130) at org.junit.platform.launcher.core.DefaultLauncher.discoverRoot(DefaultLauncher.java:117) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:90) at org.jetbrains.spek.tooling.runner.junit.JUnitPlatformSpekRunner.run(JUnitPlatformSpekRunner.kt:107) at org.jetbrains.spek.tooling.MainKt.main(Main.kt:58) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)
build.gradle
`buildscript{
ext {
ext.kotlin_version = "1.1.50"
ext.spek_version = "1.1.5"
}

repositories{
    google()
    jcenter()
    maven { url "http://dl.bintray.com/jetbrains/spek" }
}
dependencies{
    classpath 'com.android.tools.build:gradle:3.0.0'
    classpath 'com.google.guava:guava:20.0'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    classpath "de.mannodermaus.gradle.plugins:android-junit5:1.0.0"
    classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.0'
    classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlin_version"
    classpath 'com.google.gms:google-services:3.1.1'
    classpath 'io.fabric.tools:gradle:1.+'
}

} app/build.gradle apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-allopen'
apply plugin: 'io.fabric'
apply plugin: "de.mannodermaus.android-junit5"

android{
compileSdkVersion 26
buildToolsVersion "26.0.2"

sourceSets {
    main.java.srcDirs += 'src/main/java'
    test.java.srcDirs += 'src/test/java'
}

}

junitPlatform {
filters {
engines {
include 'spek'
}
}
}

dependencies{
final SUPPORT_LIBRARY_VERSION = '26.0.2'
final GOOGLE_PLAY_SERVICES = '11.4.2'

//Tests
implementation fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.0.0'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.0.0'
testImplementation 'org.junit.platform:junit-platform-launcher:1.0.0'
testCompile 'org.junit.vintage:junit-vintage-engine:4.12.0'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.0.0'
testImplementation "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
testImplementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"

testImplementation('org.jetbrains.spek:spek-api:1.1.5') {
    exclude group: 'org.jetbrains.kotlin'
}
testImplementation('org.jetbrains.spek:spek-junit-platform-engine:1.1.5') {
    exclude group: 'org.junit.platform'
    exclude group: 'org.jetbrains.kotlin'
}
testCompile 'org.mockito:mockito-core:2.10.0'
testCompile 'org.mockito:mockito-android:2.10.0'

testImplementation "org.junit.platform:junit-platform-runner:1.0.0"

androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.1', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"

/* testImplementation("org.jetbrains.spek:spek-api:$spek_version") {
exclude group: "org.jetbrains.kotlin"
}
testImplementation("org.jetbrains.spek:spek-junit-platform-engine:$spek_version") {
exclude group: "org.junit.platform"
exclude group: "org.jetbrains.kotlin"
}
testImplementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"*/

// 6. Add the dependencies on JUnit 5 & the embedded runtime for AS to the test scope
testImplementation junit5()
//testCompileOnly "de.mannodermaus.gradle.plugins:android-junit5-embedded-runtime:1.0.0-RC3-rev1"


apply plugin: 'com.google.gms.google-services'

}

afterEvaluate {
android.buildTypes.each {
def name = it.name

    def copyTestTask = project.task(type: Copy, "copyKotlin${name.capitalize()}UnitTestClasses") {
        from "build/tmp/kotlin-classes/${name}UnitTest"
        into "build/intermediates/classes/test/$name"
    }

    if (project.tasks.findByName("compile${name.capitalize()}UnitTestKotlin") != null) {
        project.tasks.getByName("compile${name.capitalize()}UnitTestKotlin").finalizedBy copyTestTask
    }

    def copyMainTask = project.task(type: Copy, "copyKotlin${name.capitalize()}Classes") {
        from "build/tmp/kotlin-classes/${name}"
        into "build/intermediates/classes/$name"
    }

    if (project.tasks.findByName("compile${name.capitalize()}Kotlin") != null) {
        project.tasks.getByName("compile${name.capitalize()}Kotlin").finalizedBy copyMainTask
    }
}

}`

Most helpful comment

Here's a working sample repo for spek https://github.com/spekframework/spek-android-example. As for the IDE issue can you try out this build: https://drive.google.com/file/d/1JpUKuiXGovg0JEtGOsj9rscjQc6YNZ1b/view?usp=sharing?

All 6 comments

hello, i have the same issue in my project, does anyone faced the same issue, that spek can't load classes !

Here's a working sample repo for spek https://github.com/spekframework/spek-android-example. As for the IDE issue can you try out this build: https://drive.google.com/file/d/1JpUKuiXGovg0JEtGOsj9rscjQc6YNZ1b/view?usp=sharing?

@raniejade thanks for the sample! Everything seems to be working with the 0.5.0 plugin. Any idea about when it will be made available via the JetBrains repositories (for direct install from Android Studio)?

Probably sometime next week, will be out for a couple of days going to publish the build when I get back. Essentially what you currently have will be the same build I'm going to publish.

thanks @raniejade the new version of the plugin fixed it :)

Just released version 0.5.1 of the plugin, it should fix the issues with AS 3.0.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alejandropg picture alejandropg  路  6Comments

pilgr picture pilgr  路  3Comments

mtrewartha picture mtrewartha  路  5Comments

fabiocarballo picture fabiocarballo  路  3Comments

mattbdean picture mattbdean  路  7Comments