Hey I have been playing with `Spek` and I can't ru...
# spek
i
Hey I have been playing with
Spek
and I can't run them for Android project.
Spek
seems to have general problem with JUnit4 runner, so I am not sure how can I use it for Android project? Here is my sample project https://github.com/igorwojda/migrate-java-tests-to-kotlin I would be grateful if some one would take a look and give some fix hints or share working Spek on Android project
a
Do you have specific error?
r
here's part of my module's build.gradle
Copy code
testImplementation "org.jetbrains.spek:spek-api:$versions.spek"
    testRuntime "org.jetbrains.spek:spek-junit-platform-engine:$versions.spek"
    testImplementation "org.junit.platform:junit-platform-console:$versions.junit_platform"
    testImplementation "org.junit.jupiter:junit-jupiter-api:$versions.junit_jupiter"
Copy code
spek        : '1.1.2',
            junit_platform  : '1.0.0-M4',
            junit_jupiter : '5.0.0-M4'
please not that this is done inside Android Studio project, but within non-Android module
As official Spek's website reads: "Android integration tests is currently not supported" http://spekframework.org/docs/latest/#_android
a
what error do you have?
i
@adambl4 Error is
Cannot add jps/kotlin-jps-plugin.jar from plugin 'Kotlin' to external compiler classpath: home directory of plugin not found
And then framework crashes
Copy code
Exception in thread "main" org.junit.platform.commons.util.PreconditionViolationException: Could not load class with name: igorwojda.com.presentertest.feature.ProfilePresenterTest_Sample1_Kotlin_Spek
	at org.junit.platform.engine.discovery.ClassSelector.lambda$getJavaClass$0(ClassSelector.java:71)
    ...
@rafal are you sure it's about module, not the test 'claspath'? Tests are in Android module indeed, but I have they are in
scr\test
, not
src\androidTest
, so they are runned loccally
r
Frankly, I'm keeping my Android module so small, that I've no need for unit tests there
Either way, ensure that you are using those versions of JUnit (later eg.
-M5
does not work with Spek 😞 )
Oh... and don't forget to put this in your top-level
build.gradle
Copy code
buildscript {
   dependencies{
      classpath "org.junit.platform:junit-platform-gradle-plugin:$versions.junit_platform"
   }
}
i
I tried all the suggestions and I am still stuck. Basicly I got
Test framework quited unexpectedly
error` I am starting to think that there maybye something wrong with my IDE/SYSTEM
@rafal or @adambl4 can you please improt this project and try to run
ProfilePresenterTestSpek
or
CorePresenterTestSpek
https://github.com/igorwojda/migrate-java-tests-to-kotlin ?
a
can do bit later
j
you also need this bit:
Copy code
junitPlatform {
        filters {
            engines {
                include 'spek'
            }
        }
    }`
a
what is your Spek plugin version?
r
run
:app:compileDebugUnitTestJavaWithJavac
and then run your Spek tests
i
@adambl4 Spek plugin ver 0.4.0, now updated to 0.4.1
So, moving forward. 1. @rafal
app:compileDebugUnitTestJavaWithJavac
- this did not helped 2. @jk Truied to add those junitplatform configurations to main project gradle file
Copy code
apply plugin: 'org.junit.platform.gradle.plugin'
junitPlatform {
        filters {
            engines {
                include 'spek'
            }
        }
    }
but is fails with an error
Copy code
Error:(31, 0) Declaring custom 'clean' task when using the standard Gradle lifecycle plugins is not allowed.
j
add it to the module containing spek tests
r
I've checked out your code. Synced gradle. Run compileUnitTest. And then I've run spek test. All tests executed and passed
i
@rafal Hmm curious... both in 'app' and 'core' modules?
Witch platform?
r
ProfilePresenterTest_Kotlin_Spek
(it's inside tests in
app
module)
i
Thanks for update. I'll take closer look at it.
@rafal
ProfilePresenterTest_Kotlin_Spek
seems to be working now indeed. Can you run tests in
CorePresenterTestSpek
? (core module)
j
these were the changes I had to make to get the tests working https://github.com/igorwojda/migrate-java-tests-to-kotlin/pull/1
i
It was Long day, but is seems everything is working Fine Now 🎉🎉🎉 Thanks a LOT guys 🙂
j
👍