Thread
#kotlintest
    h

    Hexa

    3 years ago
    I tried this and it didn't work. the doc is not very clear on how to use this projectconfig properly and there are many examples around
    import io.kotlintest.AbstractProjectConfig
    import io.kotlintest.IsolationMode
    
    object ProjectConfig : AbstractProjectConfig() {
        fun isolationMode(): IsolationMode = IsolationMode.InstancePerTest
    
        private var started: Long = 0
    
        override fun beforeAll() {
            started = System.currentTimeMillis()
        }
    
        override fun afterAll() {
            val time = System.currentTimeMillis() - started
            println("overall time [ms]: " + time)
        }
    }
    t

    thanksforallthefish

    3 years ago
    just a stupid question (as I did not try isolation mode anyway), is this class it the right package?
    package io.kotlintest.provided
    ?
    h

    Hexa

    3 years ago
    I put it under src/test/kotlin/mypackage
    i tried putting it under src/test/kotlin and it didnt work
    t

    thanksforallthefish

    3 years ago
    as far as I know it should be
    src/test/kotlin/io/kotlintest/provided
    h

    Hexa

    3 years ago
    really
    let me try that
    t

    thanksforallthefish

    3 years ago
    I use project-wise configuration for spring stuff, and under that package it is ok
    h

    Hexa

    3 years ago
    it is in src/test/kotlin/io/kotlintest/provided now and it still doesnt work, I noticed
    isolationMode
    is greyed out
    tried calling isolationMode() in the beforealll
    and it still didnt work
    am I missing something else ?
    t

    thanksforallthefish

    3 years ago
    isolationMode
    is a
    Spec
    property. not sure if you can do it at project level, but you can try
    package io.kotlintest.provided
    
    import io.kotlintest.AbstractProjectConfig
    import io.kotlintest.IsolationMode
    import io.kotlintest.Spec
    import io.kotlintest.TestCase
    
    class ProjectConfig : AbstractProjectConfig() {
    	override fun listeners() = listOf(IsolationModeListener)
    
    	object IsolationModeListener : Spec {
    		override fun isolationMode(): IsolationMode? = IsolationMode.InstancePerLeaf
    		
    		override fun closeResources() {
    			TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    		}
    
    		override fun isInstancePerTest(): Boolean {
    			TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    		}
    
    		override fun testCases(): List<TestCase> {
    			TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    		}
    	}
    }
    it might work (don't know, don't have time to test it)
    sam

    sam

    3 years ago
    In your project config add an init block that calls system.exit
    Then run your build
    That way you will know for sure if your project config is being detected
    And make sure you have the package declaration in the file like @thanksforallthefish did in his example
    Basically you must place the file in
    src/test/kotlin/io/kotlintest/provided
    and you must have package io.kotlintest.provided at the top
    h

    Hexa

    3 years ago
    thanks @sam @thanksforallthefish System.exit(0) does work so my Project config does get called
    but this thing doesnt work for me
    import io.kotlintest.AbstractProjectConfig
    import io.kotlintest.IsolationMode
    import io.kotlintest.Spec
    import io.kotlintest.TestCase
    
    class ProjectConfig : AbstractProjectConfig() {
        override fun listeners() = listOf(IsolationModeListener)
    
        object IsolationModeListener : Spec {
    
            override fun isolationMode(): IsolationMode = IsolationMode.InstancePerTest
    
            override fun closeResources() {
                TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
            }
    
            override fun isInstancePerTest(): Boolean {
                TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
            }
    
            override fun testCases(): List<TestCase> {
                TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
            }
        }
    
    //    init {
    //        System.exit(0)
    //    }
    }
    when I remove
    override fun isInstancePerTest() = true
    in one of my test classes then the test immediately fails
    i put it in
    package io.kotlintest.provided
    and its inside src/test/kotlin
    sam

    sam

    3 years ago
    I just checked and you cannot create it globally. I thought you could.
    h

    Hexa

    3 years ago
    ahhhh
    i seee
    😥
    that sucks
    sam

    sam

    3 years ago
    Yep
    I'll add it for 3.4
    in the meantime you could create your own superclass and extend from that
    abstract class MySpec : FunSpec() {
      override fun isolationMode ...
    }
    then just extend that everywhere
    Or you could use teh deprecated function for now
    h

    Hexa

    3 years ago
    while we're at it
    override fun parallelism(): Int = 100
    does not work in project config too
    i dont see my test running in parallel
    sam

    sam

    3 years ago
    specs run in parallel
    not tests
    h

    Hexa

    3 years ago
    class ProjectConfig : AbstractProjectConfig() {
        override fun parallelism(): Int = 100
    
    
    
        override fun listeners() = listOf(IsolationModeListener)
    
        object IsolationModeListener : Spec {
    
    
    
            override fun closeResources() {
                TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
            }
    
            override fun isInstancePerTest(): Boolean = true
    
            override fun testCases(): List<TestCase> {
                TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
            }
        }
    
    
    }`
    this doesnt work
    specs?
    sam

    sam

    3 years ago
    you can't do what you're doing
    specs are test files
    h

    Hexa

    3 years ago
    you mean if I have class1😒houldSpec() and class2😒houldSpec()
    then they should run in parallel?
    sam

    sam

    3 years ago
    yes
    h

    Hexa

    3 years ago
    each class will run in parallel?
    sam

    sam

    3 years ago
    yes
    h

    Hexa

    3 years ago
    well they are not running in parallel
    sam

    sam

    3 years ago
    but tests inside each class will always be ordered
    h

    Hexa

    3 years ago
    i got multilple test classes
    sam

    sam

    3 years ago
    hmm
    can you open up a bug report with a sample project that fails ?
    h

    Hexa

    3 years ago
    testImplementation(
                'org.junit.jupiter:junit-jupiter-api:5.4.2',
                'org.junit.jupiter:junit-jupiter-engine:5.4.2',
                'org.junit.vintage:junit-vintage-engine:5.4.2'
        )
    
        testImplementation 'io.kotlintest:kotlintest-runner-junit5:3.3.2'
        testImplementation "io.mockk:mockk:1.9.2"
    these are my dependencies
    sam

    sam

    3 years ago
    are you using junit
    if not get rid
    h

    Hexa

    3 years ago
    yea??
    junit5
    useJUnitPlatform()
    sam

    sam

    3 years ago
    Yes keep useJUnitPlatform
    but yyou don't need jupiter deps
    I'm at work so can't help further until later.
    h

    Hexa

    3 years ago
    i do
    see above
    dependencies
    shame about
    parallelism()
    would love to see it work
    sam

    sam

    3 years ago
    It does work
    Something is just setup wrong, there's plenty of tests for parallelism
    I'll help later 🙂
    h

    Hexa

    3 years ago
    Okay thanks. I'm using Gradle4.9, wondering if I need to use Gradle 5+
    I'll try later as well