I tried this and it didn't work. the doc is not ve...
# kotlintest
h
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
Copy code
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
just a stupid question (as I did not try isolation mode anyway), is this class it the right package?
package io.kotlintest.provided
?
h
I put it under src/test/kotlin/mypackage
i tried putting it under src/test/kotlin and it didnt work
t
as far as I know it should be
src/test/kotlin/io/kotlintest/provided
h
really
let me try that
t
I use project-wise configuration for spring stuff, and under that package it is ok
h
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
isolationMode
is a
Spec
property. not sure if you can do it at project level, but you can try
Copy code
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)
s
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
thanks @sam @thanksforallthefish System.exit(0) does work so my Project config does get called
but this thing doesnt work for me
Copy code
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
s
I just checked and you cannot create it globally. I thought you could.
h
ahhhh
i seee
😥
that sucks
s
Yep
I'll add it for 3.4
in the meantime you could create your own superclass and extend from that
Copy code
abstract class MySpec : FunSpec() {
  override fun isolationMode ...
}
then just extend that everywhere
Or you could use teh deprecated function for now
h
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
s
specs run in parallel
not tests
h
Copy code
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?
s
you can't do what you're doing
specs are test files
h
you mean if I have class1:shouldSpec() and class2:shouldSpec()
then they should run in parallel?
s
yes
h
each class will run in parallel?
s
yes
h
well they are not running in parallel
s
but tests inside each class will always be ordered
h
i got multilple test classes
s
hmm
can you open up a bug report with a sample project that fails ?
h
Copy code
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
s
are you using junit
if not get rid
h
yea??
junit5
useJUnitPlatform()
s
Yes keep useJUnitPlatform
but yyou don't need jupiter deps
I'm at work so can't help further until later.
h
i do
see above
dependencies
shame about
parallelism()
would love to see it work
s
It does work
Something is just setup wrong, there's plenty of tests for parallelism
I'll help later 🙂
h
Okay thanks. I'm using Gradle4.9, wondering if I need to use Gradle 5+
I'll try later as well