Closed davidsowerby closed 5 years ago
You have to include the correct test engines for them. http://junit.org/junit5/docs/current/user-guide/#dependency-metadata
If you're using JUnit 4 you just probably need to include the vintage test engine. Make sure it's x.x.x-M4
release.
I added
testRuntime 'org.junit.vintage:junit-vintage-engine:4.12.0-M4'
but that made no difference
Ah, got it, need to add to the filter:
junitPlatform {
filters {
engines {
include 'spek'
include 'junit-vintage'
}
}
}
But that now excludes the Spek tests, I'm getting only Spock and JUnit. Tried this as well:
junitPlatform { filters { engines { include 'spek','junit-vintage' } } }
@artem-zinnatullin can you help out? Never tried using more that one test engine.
@raniejade we don't have non-Spek JUnit4 tests mixed with Spek…
Ok, I will drop Spek from this project, I have too many Spock and JUnit tests to even consider converting them.
Will we be able to run JUnit / Spock tests in the same build as Spek once #222 is released?
@davidsowerby I'm going to take a look, it should be possible with the current version.
@davidsowerby tried it on a personal project.
group = 'org.pandaframework'
version = "0.1.0"
buildscript {
repositories {
mavenCentral()
maven {
url "https://dl.bintray.com/kotlin/kotlin-eap-1.1"
}
}
dependencies {
classpath "io.spring.gradle:dependency-management-plugin:1.0.0.RC2"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.0-M3'
}
}
apply plugin: "kotlin"
apply plugin: "idea"
repositories {
mavenCentral()
maven {
url "https://dl.bintray.com/jetbrains/spek"
}
maven {
url "https://dl.bintray.com/kotlin/kotlin-eap-1.1"
}
}
apply plugin: 'org.junit.platform.gradle.plugin'
junitPlatform {
platformVersion '1.0.0-M3'
filters {
engines {
include 'spek', 'junit-vintage'
}
}
}
apply plugin: "io.spring.dependency-management"
dependencyManagement {
dependencies {
dependency "com.natpryce:hamkrest:1.1.0.0"
dependency "com.winterbe:expekt:0.2.0"
dependencySet(group: 'org.junit.platform', version: '1.0.0-M3') {
entry 'junit-platform-engine'
entry 'junit-platform-runner'
entry 'junit-platform-launcher'
}
dependency 'org.junit.vintage:junit-vintage-engine:4.12.0-M3'
dependencySet(group: 'org.jetbrains.spek', version: '1.1.0-beta3') {
entry ('spek-api') {
exclude group: 'org.jetbrains.kotlin'
}
entry ('spek-subject-extension') {
exclude group: 'org.jetbrains.kotlin'
}
entry ('spek-junit-platform-engine') {
exclude group: 'org.jetbrains.kotlin'
}
}
dependency "com.nhaarman:mockito-kotlin:1.2.0"
dependencySet(group: 'org.jetbrains.kotlin', version: ext.kotlinVersion) {
entry 'kotlin-stdlib'
entry 'kotlin-reflect'
}
}
}
configurations {
integrationTestCompile {
extendsFrom testCompile
}
integrationTestRuntime {
extendsFrom testRuntime
}
}
sourceSets {
integrationTest {
kotlin {
srcDirs += 'src/integrationTest/kotlin'
}
compileClasspath += sourceSets.main.output
}
}
idea {
module {
sourceDirs -= file('src/integrationTest/kotlin')
testSourceDirs += file('src/integrationTest/kotlin')
}
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib"
compile "org.jetbrains.kotlin:kotlin-reflect"
testCompile 'com.natpryce:hamkrest'
testCompile 'org.jetbrains.spek:spek-api'
testCompile 'com.winterbe:expekt'
testCompile 'com.nhaarman:mockito-kotlin'
testCompile 'org.jetbrains.spek:spek-subject-extension'
testCompile 'org.junit.vintage:junit-vintage-engine'
testRuntime 'org.jetbrains.spek:spek-junit-platform-engine'
}
apply plugin: 'maven-publish'
task sourceJar(type: Jar) {
from sourceSets.main.allSource
}
publishing {
publications {
maven(MavenPublication) {
artifactId 'panda-ecs'
from components.java
artifact sourceJar {
classifier "sources"
}
}
}
}
When doing ./gradlew test
it runs everything - Spek and JUnit4 tests.
@raniejade Thanks for your help on this one, it is much appreciated ... I tried this, but actually could not run any tests at all - I suspect I have missed something, but this setup is very complicated just to run existing tests alongside Spek.
I don't really have much time to spend on this just now - so I will park Spek for now, and try and get back to it later ... or you can close this issue if you wish.
@davidsowerby I use gradle 4.6 instead of the gradle plugin, it works for me I mixed junit4 and spek testcases
@kintomiko Thanks for that. I may try that. I did in fact start using Spek, and am gradually migrating tests to it, but have kept them in a separate project for now.
It took me a while to get back to this, but with the setup provided by @raniejade and the Gradle version tip provided by @kintomiko , I now have this working.
I have also updated the versions and am using:
spek 1.1.5 junit-platform: 1.0.3 vintage-engine: 4.12.3
I have similar issue to this one, I'm trying out Spek in Android studio on existing project, I've done integration as explained here and everything worked fine until I tried running existing JUnit 4 tests. It kept running spek tests instead of junit ones.
After some attempts, I've figured out that whenever spek-runner-junit5
dependency is included, IDE(AS 3.2.1) and gradle (4.10.3) run only spek tests and ignore junit ones. Changing junitPlatform/filters/engines to include junit-vintage (or not include spek) have no impact at all. It's looks like spek-runner-junit5 is taking over tests no matter what.
Btw, hi @artem-zinnatullin, just saw your KotlinConf 2017 Spek presentation, good work.
@mmitic-lotusflare it's fixed in master, I'm hoping to release a new version soon - just got back from my vacation.
Oops, wrong button..
Thanks, @raniejade, I'll watch the releases.
It still doesn't work, even after 2.0 release. When we can expect this?
@raniejade I've tried 2.0.0 release, it's better now, I can run individual JUnit tests (albeit it takes more time to initialize test framework, could be due to switch to JUnit 5). Running group of JUnit tests doesn't work (No tests were found) and "Run Spek tests in ..." has taken over usual "Run tests in ...", regardless of whether target contains Spek tests or not:
Can you open another issue? I’ll take a look tonight. If you can also share a sample project, that will be very helpful.
I'll try when I find the time. What I tested with is a closed-source project, so I'll make a new sample project for this.
Do you have something similar for Maven setups? I'm having the same problem of not being able to run JUnit tests (written in Groovy) along with Spek tests (written in Kotlin)
@argonath88 sorry no, I'm not very familiar with maven.
I did it fine on gradle and android with:
testOptions {
junitPlatform {
filters {
engines {
include 'spek2'
include 'junit-vintage'
}
}
}
and:
dependencies {
testRuntimeOnly "org.junit.vintage:junit-vintage-engine:5.3.2"
}
I have both Spock and JUnit tests in folders parallel to the Spek tests, but these are just ignored by both the IDE and Gradle CLI. Is there something else I need to configure for the JUnitPlatform?
Relevant parts of build.gradle: