In my build.gralde.kts there is a module description
val androidTest by getting {
dependencies {
implementation(kotlin("test-junit"))
implementation(AndroidTestDependencies.junit)
}
}
but in the project hierarchy it looks different than commonTest/commonMain etc. Besides, for some reason I can't run the test in this module. What could be the problem?
Can you try to set junit dependency like this:
val androidTest by getting {
dependencies {
implementation(kotlin("test-junit"))
implementation("junit:junit:4.13.2")
}
}
In my case it works fine
Related
I'm trying to setup pipeline on Jenkins for our JavaFX application. Everything works fine, but I have one problem by starting unit tests. Each test, which somehow uses JavaFX classes fails with following root cause:
Caused by: java.lang.IllegalAccessException: class net.bytebuddy.description.annotation.AnnotationDescription$ForLoadedAnnotation cannot access interface com.sun.javafx.beans.IDProperty (in module javafx.base) because module javafx.base does not export com.sun.javafx.beans to unnamed module #7ee955a8
I tried a following things:
setting env variable JAVA_OPTS
JAVA_OPTS=--module-path /path/to/javafx --add-modules javafx.controls,javafx.base
adding compiler options in gradle
tasks.withType(Test).configureEach {
doFirst {
options.compilerArgs += [
'--module-path', '/path/to/javafx',
'--add-modules', 'javafx.controls,javafx.base',
]
classpath = files()
}
}
but nothing changed. I'm using the OpenJDK compiled by Azul. I took the version with JavaFX (JDKFX) but I'm not able to make this tests running (tests without any references to JavaFX are running fine). I'm also able to compile the application. Do you have any sugestions?
The problem was, like mentioned in comments, that it should not be added to the compilerArgs but to the runtime and additionally I placed it in wrong build.gradle file. The final configuration which solved all problems was to add following to the main build.gradle file:
allprojects {
tasks.withType(Test).configureEach {
jvmArgs += [
'--add-modules', 'javafx.controls,javafx.base,javafx.graphics',
'--add-opens', 'javafx.graphics/com.sun.javafx.application=ALL-UNNAMED',
'--add-opens', 'javafx.base/com.sun.javafx.beans=ALL-UNNAMED',
]
}
}
I am working on a Kotlin project with Gradle that includes unit tests. I want to add some integration tests (or functional tests, never understood the difference between the two), but I want to be able to run them independently. Ideally, the source of the tests are in different folders.
I am using Gradle 4.5 and my build.gradle file looks something like this :
buildscript {
ext.kotlin_version = '1.2.21'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'kotlin'
apply plugin: 'application'
mainClassName = 'xyz.bobdudan.myproject.AppKt'
repositories {
maven { url "http://maven.stardog.com" }
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
testCompile 'io.kotlintest:kotlintest:2.0.7'
}
I have tried the method described here for java, but it doesn't work : the task also runs the unit tests, but they can't be found, and the integration tests are not executed at all.
What can i do ?
Edit :
Here is the result of gradle clean integTest with the solution of #lance-java:
:clean
:compileIntegTestKotlin
:compileIntegTestJava NO-SOURCE
:processIntegTestResources NO-SOURCE
:integTestClasses UP-TO-DATE
:integTest NO-SOURCE
Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
See https://docs.gradle.org/4.5/userguide/command_line_interface.html#sec:command_line_warnings
BUILD SUCCESSFUL in 1s
2 actionable tasks: 2 executed
So nothing is executed (I make sure that the tests are supposed to fail)
Note: I'm not a kotlin dev so will write in groovy.
You can add another SourceSet which will automatically add a JavaCompile task for the SourceSet and also a few Configuration instances to the model (eg integTestCompile, integTestCompileOnly, integTestRuntime etc)
sourceSets {
integTest {
java.srcDir 'src/integTest/java'
resources.srcDir 'src/integTest/resources'
}
}
configurations {
integTestCompile.extendsFrom compile
}
Then you can add another Test task
task integTest(type: Test) {
testClassesDir = sourceSets.integTest.output.classesDir
classpath = sourceSets.integTest.runtimeClasspath
}
You may wish to wire the integTest task into the normal DAG, or perhaps you'll leave this off and call it explicitly
check.dependsOn integTest
To tell long story short you have to:
create separate source sets,
create testTask for each test source,
set it up,
define order these tasks should be executed during build/check
and you are good to go.
Here is a guide in an answer to another question about how to do this for project using JUnit5 and Kotlin Spek test framework.
I have multi-project Gradle script. I added to the root project:
buildscript {
repositories{
...
}
dependencies { classpath("org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.2.1") }
}
apply plugin: org.sonarqube.gradle.SonarQubePlugin
sonarqube {
properties {
property "sonar.junit.reportsPath", "$projectDir/build/test-results/test"
property "sonar.host.url", "http://localhost:9000"
property "sonar.verbose", "true"
}
}
Sonarqube shows the correct number of tests, but coverage is 0.
I use Gradle 3.0, Java 1.8.0_45, Sonarqube 6.1.
Gradle console shows many "Class not found" messages.
Gradle console also shows message:
"Reports path contains no files matching TEST-.*.xml :
myPath\build\test-results\test"
, which is correct, since that particular project does not have any tests.
In my child project, I have:
apply plugin: 'java'
apply plugin: "jacoco"
jacocoTestReport {
reports {
xml.enabled = true
}
}
check.dependsOn jacocoTestReport
Run Gradle task "sonarqube" of the root project.
No SonarQube Analyzer or plugin executes your tests or the coverage calculation for you. You must do those things before analysis and feed the resulting report(s) into your analysis.
I have a task that will run the Javascript test, and I'm trying to put JSHint to verify the code after run the tests, right?
So, this is a part of my build.gradle file:
apply plugin: 'com.eriwen.gradle.js'
def jsSrcDir = "src/main/resources/static/js/"
def jsSrcTestDir = "src/test/resources/"
javascript.source {
dev {
js {
srcDir jsSrcDir
include "*.js"
}
}
test {
js {
srcDir jsSrcTestDir
include "*.js"
}
}
}
task jasmineTest(dependsOn: ['npmTest'],type: Exec)
jasmineTest.doFirst {
println "Running JSHint ----> SOURCE CODE"
commandLine "jshint", jsSrcDir
//println "Running JSHint ----> TEST CODE"
//commandLine "jshint", "src/test/resources/"
}
So, ok, it's running well, but is always failing, because JSHint are finding some improvements on my code, it's cool, but it's not my intention, I want to run the jasmine Test task, and does not matter if JSHint found or not an improvement, my task only need to fail if the test fail.
So, what I need to configure on my build gradle to put this working well?
Also, I have .jshintrc and .jshintignore configured.
Set ignoreExitValue = true in jasmineTest task.This will tell Gradle to ignore exit value else an exception thrown.
https://docs.gradle.org/current/dsl/org.gradle.api.tasks.Exec.html#org.gradle.api.tasks.Exec:ignoreExitValue
Using IntelliJ IDEA 14.0.2, I have imported a gradle java project. We have set up a sourceSet and configuration to separate integration tests from unit tests. (our integration tests are in the test source tree, but in their own package). Relevant bits from the build.gradle are:
sourceSets {
test {
java {
exclude '**/it/**'
}
}
integTest {
java {
srcDir 'src/test/java'
include '**/it/**'
}
resources {
srcDir 'src/test/resources'
}
compileClasspath += sourceSets.main.output + sourceSets.test.output + configurations.testRuntime
runtimeClasspath += sourceSets.main.output + sourceSets.test.output + configurations.testRuntime
}
}
configurations {
integTestCompile.extendsFrom testCompile
integTestRuntime.extendsFrom testRuntime
}
idea {
module {
scopes.TEST.plus += [ configurations.integTestCompile ]
}
}
task integTest(type: Test) {
testClassesDir = sourceSets.integTest.output.classesDir
classpath = sourceSets.integTest.runtimeClasspath
}
This works fine from the command line. But when I open up the source of an integration test in IntelliJ and right-click to run it, IntelliJ launches the "test" task rather than the "integTest" task. How do I get IntelliJ to launch the correct task?
Alternatively, how can I make the test task delegate to another task based on the contents of the "--tests " arg?
Follow this: gradle settings > Gradle > Runner and check Delegate IDE build/run actions to gradle. Then apply and Ok.
Good luck!
Right-click on the test on file and you should see a menu option for Create Run Configuration >. Select that an in the dialog, modify the Tasks option. Change that to integTest and click OK. From that point, you might have to run the test using the menu system rather than the context system. i.e. Run > Run...
My solution is to configure IntelliJ to not use Gradle as a test runner, but to execute the tests with the built-in JUnit runner. This is just a configuration option in IntelliJ IDEA at the Gradle settings.
See https://www.jetbrains.com/help/idea/gradle-settings.html#gradle_tests for details.