logo
Tags down

shadow

Not able to run unit tests on kotlin Multiplatform project


By : Heather Moore
Date : September 16 2020, 02:00 AM
wish help you to fix your issue check your name of class test, it could be: com.package.example.Tests or click right on your class and make the configuration:
code :
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'


Share : facebook icon twitter icon

How to make my JS tests appear in Kotlin Multiplatform project


By : user1875705
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , As stated by Kotlin Multiplatform Tutorial
code :
plugins {
    id 'kotlin-multiplatform' version '1.3.10' //I'm using the released version of plugin,
                                               //but it seems that they have same API
    id 'com.moowork.node' version '1.2.0' //plugin for installing node
                                          //and running node and npm tasks
}
repositories {
    mavenCentral()
}
group 'com.example'
version '0.0.1'

apply plugin: 'maven-publish'

final kotlinRuntimeVersion = '1.3.10'

final nodeVersion = '11.2.0'
final nodeWorkingDir = project.buildDir
final nodeModules = "$nodeWorkingDir/node_modules"
final mochaVersion = '5.2.0'
final pathSeparator = System.properties["path.separator"]

kotlin {
    targets {
        fromPreset(presets.jvm, 'jvm')
        fromPreset(presets.js, 'js') {
            [compileKotlinJs, compileTestKotlinJs].each { configuration ->
                configuration.kotlinOptions {
                    moduleKind = 'umd'
                }
            }
        }
    }
    sourceSets {
        commonMain {
            dependencies {
                implementation 'org.jetbrains.kotlin:kotlin-stdlib-common'
            }
        }
        commonTest {
            dependencies {
                implementation 'org.jetbrains.kotlin:kotlin-test-common'
                implementation 'org.jetbrains.kotlin:kotlin-test-annotations-common'
            }
        }
        jvmMain {
            dependencies {
                implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
            }
        }
        jvmTest {
            dependencies {
                implementation 'org.jetbrains.kotlin:kotlin-test'
                implementation 'org.jetbrains.kotlin:kotlin-test-junit'
            }
        }
        jsMain {
            dependencies {
                implementation 'org.jetbrains.kotlin:kotlin-stdlib-js'
            }
        }
        jsTest {
            dependencies {
                implementation 'org.jetbrains.kotlin:kotlin-test-js'
            }
        }
    }
}

//Workaround to copy kotlin libraries so they are visible during testing
def jsLibDir = "$compileKotlinJs.destinationDir/lib"
def jsTestLibDir = "$compileTestKotlinJs.destinationDir/lib"
configurations {
    jsLibs
    jsTestLibs
}
dependencies {
    jsLibs "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlinRuntimeVersion"
    jsTestLibs "org.jetbrains.kotlin:kotlin-test-js:$kotlinRuntimeVersion"
}
task copyJsDependencies(type: Copy, dependsOn: compileKotlinJs) {
    configurations.jsLibs.each {
        from zipTree(it.absolutePath).matching { include '*.js'}
    }
    into jsLibDir
}
jsMainClasses.dependsOn copyJsDependencies
task copyJsTestDependencies(type: Copy) {
    configurations.jsTestLibs.each {
        from zipTree(it.absolutePath).matching { include '*.js'}
    }
    into jsTestLibDir
}
jsTestClasses.dependsOn copyJsTestDependencies

//Use mocha to run js tests
node {
    version = nodeVersion
    download = true
    workDir = file("$project.buildDir/nodejs")
    nodeModulesDir = file(nodeWorkingDir)
}
task installMocha(type: NpmTask, group: 'npm') {
    outputs.dir "$nodeModules/mocha"
    args = ['install', "mocha@$mochaVersion"]
}
task runMocha(type: NodeTask, dependsOn: [installMocha, jsMainClasses, jsTestClasses], group: 'npm') {
    environment = [ "NODE_PATH": "$jsLibDir$pathSeparator$jsTestLibDir$pathSeparator$compileKotlinJs.destinationDir" ]
    script = file("$nodeWorkingDir/node_modules/mocha/bin/mocha")
    args = [compileTestKotlinJs.outputFile]
}
jsTest.dependsOn runMocha
pluginManagement {
    resolutionStrategy {
        eachPlugin {
            if (requested.id.id == "kotlin-multiplatform") {
                useModule("org.jetbrains.kotlin:kotlin-gradle-plugin:${requested.version}")
            }
        }
    }
}
rootProject.name = 'test'

Kotlin-multiplatform: How to execute iOS unit tests


By : user2247688
Date : March 29 2020, 07:55 AM
around this issue Currently the kotlin-multiplatform plugin supports only running tests for host platforms (e.g. macOS or Windows). But you can manually add a task for executing iOS tests on a simualtor:
code :
task iosTest {
    def device = project.findProperty("iosDevice")?.toString() ?: "iPhone 8"
    dependsOn 'linkTestDebugExecutableIos'
    group = JavaBasePlugin.VERIFICATION_GROUP
    description = "Runs tests for target 'ios' on an iOS simulator"

    doLast {
        def binary = kotlin.targets.ios.binaries.getExecutable('test', 'DEBUG').outputFile
        exec {
            commandLine 'xcrun', 'simctl', 'spawn', device, binary.absolutePath
        }
    }
}

Kotlin Multiplatform Gradle unit test not resolving kotlin.test reference


By : user2856054
Date : March 29 2020, 07:55 AM
I wish this help you As it turns out, I had some conflicting dependencies in my commonTest source set after all. The 'test' dependency was conflicting with the 'test-common', which led to problems that were buried in some build logs. After deleting the extra dependencies, the build succeeded and the test ran. (and passed!)
code :
sourceSets {
   ...
   commonTest {
      dependencies {
         //only these are needed
         implementation kotlin('test-common')
         implementation kotlin('test-annotations-common')
      }
   }
   ...
}

How to do Unit Testing in Kotlin/Native Multiplatform?


By : Karl Holland
Date : October 13 2020, 01:00 PM
fixed the issue. Will look into that further I was able to get this to work based off of the mpp-example git repo. My gradle file looks like:
code :
kotlin {
    sourceSets {
        commonTest {
            dependencies {
                implementation kotlin('test-common')
                implementation kotlin('test-annotations-common')
            }
        }
        iosTest {
            dependsOn commonTest //possibly not needed
        }
    }
}
task iosTest {
    def device = project.findProperty("iosDevice")?.toString() ?: "iPhone 8"
    dependsOn 'linkTestDebugExecutableIos'
    group = JavaBasePlugin.VERIFICATION_GROUP
    description = "Runs tests for target 'ios' on an iOS simulator"

    doLast {
        def binary = kotlin.targets.ios.binaries.getExecutable('test', 'DEBUG').outputFile
        exec {
            commandLine 'xcrun', 'simctl', 'spawn', device, binary.absolutePath
        }
    }
}

Kotlin Multiplatform: How to mock objects in a unit test for iOS


By : Robert Travis Shelto
Date : September 30 2020, 05:00 AM
I hope this helps . I looked around and asked in Kotlin' General slack which by the way is a great space where you can ask directly the Kotlin devs and the enthusiasts Kotlin language related questions including multi-platform stuff.
But as for the time I'm writing this, I Don't think you can mock for the common module with Mockk or any other mocking library.
Related Posts Related Posts :
  • Kotlin, unresolved reference on everything in VSCode
  • brief function code for null check in kotlin
  • How to capture an argument that was passed to a mocked function and return it?
  • Issue when trying to import Jacoco code coverage to SonarQube: Cannot import coverage information for file, coverage dat
  • Proposed change of `equals` to `==` can't be applied to Char and String?
  • How to use kotlin's default parameter only if the input is not null?
  • Please Explain to me this kotlin statement?
  • How to check if a string is a valid email in android?
  • This annotation is not applicable to target member property without backing field or delegate
  • How to split on unicode whitespace in kotlin
  • How can Kotlin's Set be covariant when contains() takes E?
  • Kotlin inline class in JUnit tests
  • Lambda as a function parameter -> accept methods only from particular class
  • Kotlin - How do I concatenate a String to an Int value?
  • Why I Cannot Access to this function?
  • Kotlin test, how to run BeforeEach with DescribeSpec test style
  • Convince Kotlin compiler map has a key
  • how do you declare static property in kotlin?
  • How can i call an interface in kotlin?
  • Check if any array item is not empty
  • kotlin, where the return from inside the let go
  • Kotlin: Should mutableList be declared as Val or Var?
  • Convert Long to String in Kotlin
  • Extension property inside class: Unresolved reference: errorResponse
  • How to extend enums in Kotlin?
  • Idiomatic way in kotlin to transform/append to a list?
  • How to avoid nest 「null check」by "?.let"?
  • How to simply add another source to MediatorLiveData in kotlin?
  • Convert Set<Int> to varargs efficiently in Kotlin
  • Getting an error Using 'body(): ResponseBody?' is an error. moved to val with okhttp
  • Kotlin String to Int or zero (default value)
  • Return value only of the faster coroutine
  • Is there a Kotlin Coroutines Channel equivalent of RxJava's onDispose?
  • Create fat jar from kotlin multiplatform project
  • Short circuiting operation in Kotlin sequences
  • How to output deprecation warnings for Kotlin code?
  • Why does generated getter method have dollar signs in it?
  • For a final class why does when complain?
  • Reference value of constant with KDoc
  • How to create this coroutines in kotlin?
  • OkHttp: NoSuchMethodError copyInto in TlsUtil
  • Why do unreachable statements method not result in a compilation error?
  • Static/Const map key check at compile time
  • Escaping double quotes inside backticks
  • Does Kotlin have primitive types?
  • What is exactly null in kotlin and why i can't cause NPE with it?
  • Why would you use a Kotlin companion object rather than an initializer block for creation?
  • how to use operator overloading in Kotlin to divide a number by a numeric vector
  • How to use get() with backing fields in kotlin
  • How to map string to function and call it later
  • Kotlin enum constructor argument 'must be initialized' with companion object constant without qualifier name
  • Please explain to me class delegation in Kotlin
  • Error:(1, 41) Kotlin: Symbol is declared in module 'jdk.internal.opt' which does not export package 'jdk.i
  • How to properly make blocking service calls with Kotlin coroutines?
  • Gson SerializedName in a Kotlin interface
  • Kotlin convert FileTime to day, month, year
  • Kotlin how to move a file to a other directory?
  • If first param is true, then must pass second param in function
  • MutableLiveData for collections
  • How to replace long chain of forEach{} statements in Kotlin?
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk