-
Notifications
You must be signed in to change notification settings - Fork 181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Android Studio 3.0 #256
Comments
Can you try using JUnit Platform |
Problem persists. I tried out different run configs. First outputs stacktrace like above. Second:
I pushed everything to the repository. |
JUnit 5 supports gradle for java projects. Gradle for Android projects has some differences that break compatibility. Even if you are using a java module in your project, Android Studio uses an IntelliJ build that depends on APIs of an outdated JUnit 5 Milestone. Your tests will fail when executed from Android Studio directly. If you intend to use only Android modules in your project, the android-junit plugin by @aurae solves all the problems above. The github project has a sample showing how your project can be configured to run JUnit 5 based tests. |
Hmm thanks for this. I now get a nice output in my CLI However still unable to get this to run in Android Studio 3.0.0-beta5.
Would be nice to see a complete sample with Kotlin + Spek + AndroidJUnit5 support repo that actually runs in Android Studio 3.0.0 Thanks Tim Rijckaert |
Can you try using |
Can you check your dependencies? Let me know if you're pulling in JUnit Platform |
Also, if you're using android-junit5 with Android Studio, please make sure to add the embedded runtime for JUnit 5 as another compile-only dependency to your build script. You can check my readme for more details on this, but basically AS didn't keep up with the changing API of the JUnit milestone releases, and is still stuck with an older (and now, incompatible) bundled version. |
I have updated the JUnit Platform dependency to |
@timrijckaert https://github.com/paulinabls/hangman here you can find a working config for AS 3.0 Preview and Spek v 1.1.2 . I couldn't make it work with Spek v 1.1.4. See |
@timrijckaert Interesting that adding the runtime doesn't seem to be working for you. In the android-junit5 example project, I can fix or break unit test execution in AS 3.0 just by commenting out the |
I've found another thing that might be causing your issue, and it's related to how the artifact was published to jcenter. Can you try pulling in the maven { url "https://dl.bintray.com/aurae/maven" } If that's actually the fix, I'll prepare a hotfix for jcenter. |
Does not seem to do anything. |
Very sorry, haven't look at this any further yet. My local android dev environment is broken and I haven't find time yet to fix it. |
@timrijckaert can you add this to afterEvaluate {
compileDebugUnitTestKotlin {
finalizedBy copyKotlinDebugUnitTestClasses
}
compileDebugKotlin {
finalizedBy copyKotlinDebugClasses
}
}
task copyKotlinDebugUnitTestClasses(type: Copy) {
from "build/tmp/kotlin-classes/debugUnitTest"
into "build/intermediates/classes/test/debug"
}
task copyKotlinDebugClasses(type: Copy) {
from "build/tmp/kotlin-classes/debug"
into "build/intermediates/classes/debug"
} Apparently android and kotlin has their own output directory, when running from AS compiled kotlin and android outputs are not consolidated hence the |
Let's see if AS 3.0 Beta 7 fixes this https://issuetracker.google.com/issues/64804587. |
I had already added this albeit in another form. afterEvaluate {
android.buildTypes.all {
def name = it.name
def copyTask = project.task(type: Copy, "copyKotlin${name.capitalize()}UnitTestClasses") {
from "build/tmp/kotlin-classes/${name}UnitTest"
into "build/intermediates/classes/test/$name"
}
project.tasks.getByName("compile${name.capitalize()}UnitTestSources").finalizedBy copyTask
}
} Could you setup a test Android project with a simple Spek test that is able to run in AS 3.0 Beta 6-7? |
build.gradle // Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.1.50'
repositories {
google()
jcenter()
maven { url "http://dl.bintray.com/jetbrains/spek" }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-beta6'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "de.mannodermaus.gradle.plugins:android-junit5:1.0.0"
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
} app/build.gradle apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: "de.mannodermaus.android-junit5"
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.tvcoursework.kotlinintrocourse"
minSdkVersion 26
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
test.java.srcDirs += 'src/test/kotlin'
}
}
junitPlatform {
filters {
engines {
include 'spek'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:26.1.0'
testImplementation 'junit:junit:4.12'
testImplementation "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
testImplementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
testImplementation('org.jetbrains.spek:spek-api:1.1.5') {
exclude group: 'org.jetbrains.kotlin'
}
testImplementation('org.jetbrains.spek:spek-junit-platform-engine:1.1.5') {
exclude group: 'org.junit.platform'
exclude group: 'org.jetbrains.kotlin'
}
testImplementation "org.junit.platform:junit-platform-runner:1.0.0"
androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.1', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
}
afterEvaluate {
compileDebugUnitTestKotlin {
finalizedBy copyKotlinDebugUnitTestClasses
}
compileDebugKotlin {
finalizedBy copyKotlinDebugClasses
}
}
task copyKotlinDebugUnitTestClasses(type: Copy) {
from "build/tmp/kotlin-classes/debugUnitTest"
into "build/intermediates/classes/test/debug"
}
task copyKotlinDebugClasses(type: Copy) {
from "build/tmp/kotlin-classes/debug"
into "build/intermediates/classes/debug"
} |
Yes! Thanks for these. |
(Copied from #271 for future reference by anybody who might stumble upon this) The proposed task declarations will only copy over classes in the build.gradle: buildscript {
ext.kotlin_version = "1.1.50"
ext.spek_version = "1.1.5"
dependencies {
// 1. Add the android-junit5 Gradle plugin as a classpath dependency
classpath "de.mannodermaus.gradle.plugins:android-junit5:1.0.0"
}
} <module>/build.gradle: // 2. Apply the android-junit5 plugin alongside your app's plugins
apply plugin: "de.mannodermaus.android-junit5"
android {
// 3. Extend the Java source set with the Kotlin folders
sourceSets {
main.java.srcDirs += "src/main/kotlin"
test.java.srcDirs += "src/test/kotlin"
}
}
// 4. Configure spek's TestEngine to be detected by JUnit 5
junitPlatform {
filters {
engines {
include "spek"
}
}
}
dependencies {
// 5. Add the dependencies on spek & its required co-dependencies to the test scope
testImplementation("org.jetbrains.spek:spek-api:$spek_version") {
exclude group: "org.jetbrains.kotlin"
}
testImplementation("org.jetbrains.spek:spek-junit-platform-engine:$spek_version") {
exclude group: "org.junit.platform"
exclude group: "org.jetbrains.kotlin"
}
testImplementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
// 6. Add the dependencies on JUnit 5 & the embedded runtime for AS to the test scope
testImplementation junit5()
testCompileOnly "de.mannodermaus.gradle.plugins:android-junit5-embedded-runtime:1.0.0-RC3-rev1"
}
// 7. Finally, configure AS to copy over Kotlin classes for each build type to where the IDE can pick them up
afterEvaluate {
android.buildTypes.each {
def name = it.name
def copyTestTask = project.task(type: Copy, "copyKotlin${name.capitalize()}UnitTestClasses") {
from "build/tmp/kotlin-classes/${name}UnitTest"
into "build/intermediates/classes/test/$name"
}
project.tasks.getByName("compile${name.capitalize()}UnitTestKotlin").finalizedBy copyTestTask
def copyMainTask = project.task(type: Copy, "copyKotlin${name.capitalize()}Classes") {
from "build/tmp/kotlin-classes/${name}"
into "build/intermediates/classes/$name"
}
project.tasks.getByName("compile${name.capitalize()}Kotlin").finalizedBy copyMainTask
}
} |
Can you build & run your apk when 7. is added? I receive the following gradle error
Using AS 3.0 Beta 7 |
Nope indeed it is broken again. :'(
|
With this I get DexException on assemble. afterEvaluate {
compileDebugUnitTestKotlin {
finalizedBy copyKotlinDebugUnitTestClasses
finalizedBy copyKotlinDebugClasses
}
}
task copyKotlinDebugUnitTestClasses(type: Copy) {
from "build/tmp/kotlin-classes/debugUnitTest"
into "build/intermediates/classes/test/debug"
}
task copyKotlinDebugClasses(type: Copy) {
from "build/tmp/kotlin-classes/debug"
into "build/intermediates/classes/debug"
} |
Hiya,
I'm a bit confused how the setup of Spek for Android projects should be.
Previously in Android Studio 2.3.3 everything seemed to be working just fine with the Spek plugin installed.
Following the documentation I retried from scratch in a clean new project since I can't share my particular project.
The problem seems to exist there as well.
Upon running I get:
WARNING: TestEngine with ID 'spek' failed to discover tests org.junit.platform.commons.util.PreconditionViolationException: Could not load class with name: vrt.be.rijckaert.tim.spekproblem.CalculatorSpec
I also tried to add a
compileDebugUnitTestSources
Gradle task before running the unit tests.You can find the full example here
How can I get Spek to run with Android Studio 3.0.0 ?
To my understanding something goes wrong with the new bundled JUnit 5 runner?
Thanks in advance
Tim
The text was updated successfully, but these errors were encountered: