1

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)

2 Answers 2

1

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 
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for the response, but this doesn't work. The update on my post shows the output of the command gradle clean integTest
:integTest NO-SOURCE means there's nothing in src/integTest/java so it didn't do anything. See also nebula-integtest-plugin which does everything I've mentioned using a single line
I don't think so, because I explicitly declared the source directory and if I make a mistake in the file it will not compile.
Have you put a .java file (with a junit @Test annotation) in src/integTest/java?
1

To tell long story short you have to:

  1. create separate source sets,
  2. create testTask for each test source,
  3. set it up,
  4. 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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.