kotest: Could not find method test()

I probably do something wrong, however I have been stuck on this one for a while now.

I set up an empty project to reproduce my issue myproject/build.gradle:

buildscript { 
    ext.kotlin_version = '1.3.20' 
    repositories { 
        google() 
        jcenter()  
    } 
    dependencies { 
        classpath 'com.android.tools.build:gradle:3.3.0' 
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 
    } 
} 
 
allprojects { 
    repositories { 
        google() 
        jcenter() 
    } 
} 
 
task clean(type: Delete) { 
    delete rootProject.buildDir 
} 

And I follow the documentation in myproject/app/build.gradle:

apply plugin: 'com.android.application' 
apply plugin: 'kotlin-android' 
apply plugin: 'kotlin-android-extensions' 
 
android { 
    compileSdkVersion 28 
    defaultConfig { 
        applicationId "com.example.myapplication" 
        minSdkVersion 15 
        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' 
        } 
    } 
} 
 
test {
    useJUnitPlatform()
}

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' 
    testImplementation 'junit:junit:4.12' 
    androidTestImplementation 'com.android.support.test:runner:1.0.2' 
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 
    testImplementation 'io.kotlintest:kotlintest-runner-junit5:3.2.1' 
} 

And When I try to build I get the following error: (–stacktrace --debug --info are not very helpful)

Could not find method test() for arguments [build_61tpwz9zzo2o2j2cb2rqxat9d$_run_closure1@1c5c85d4] on project ':app' of type org.gradle.api.Project.

I use gradle 4.10.3 and android studio 3.3

Anything I’m doing wrong?

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 19 (16 by maintainers)

Most upvoted comments

Did you check out https://github.com/kotlintest/kotlintest#gradle I updated the documentation following my trouble.

Basically you should add testImplementation 'io.kotlintest:kotlintest-runner-junit5:3.3.2' in the dependencies section, and this:

android {
  ...
    testOptions {
        unitTests.all {
            useJUnitPlatform()
        }
    }
android {
   testOptions {
          unitTests.includeAndroidResources = true
          unitTests.all {
              useJUnitPlatform()
              reports {
                  junitXml.enabled = true
                  html.enabled = false
              }
              testLogging {
                  events "passed", "skipped", "failed"
  
                  // to run JUnit 3/4 tests:
                  testImplementation("junit:junit:4.12")
                  testRuntime("org.junit.vintage:junit-vintage-engine:5.7.0")
              }
          }
      }
}

If it’s okay I’m just going to leave this here for the next person who stumbles on this thread doing the same thing as me.

I was using this SO Thread about how to display pretty-er Gradle test outputs. They use the test block to set up testing options for better Gradle logs:

test {
    testLogging {
        events "passed", "skipped", "failed", "standardOut", "standardError"
    }
}

Which I think is a root project configuration, but I was having the same issue in my root build.gradle. I’m not sure if this is an issue with the Android gradle setup, but I was able to do what @jeremad suggested and included my configuration in the android block under testOptions

android {
    // ...
    testOptions {
        unitTests.all {
            testLogging {
                events "passed", "skipped", "failed", "standardOut", "standardError"
            }
        }
    }
}