question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Test not found when run from gradle

See original GitHub issue

Using Gradle 4.6 and KotlinTest 3.0.1, executing gradlew clean test returns a bunch of warnings from org.reflections, but does not run any tests. When run using the junit runner within intellij, it works fine.

I’m currently trying to run a spring-boot integration test, shown below. I’ve also listed my build.gradle for reference.

test class:

@SpringBootTest
class SampleRepositoryIntegrationSpec : BehaviorSpec() {

	override fun listeners(): List<TestListener> = listOf(SpringListener)

	@Autowired
	lateinit var repository: SampleRepository

	init {
		given("A valid instance of Sample") {
			val expected = Sample(comment = UUID.randomUUID().toString())

			When("it is persisted") {
				val persisted = repository.save(expected)

				then("a valid uuid has been generated") {
					persisted.uuid shouldNotBe null
				}

				When("it is queried by uuid") {
					val found = repository.findOne(persisted.uuid)

					then("is found") {
						found shouldNotBe null
						found.uuid shouldBe persisted.uuid
					}
				}
			}
		}
	}
}

Build.gradle:

buildscript { ext { spring_boot_version = ‘1.5.10.RELEASE’ spring_version = ‘4.3.14.RELEASE’ kotlin_version = ‘1.2.31’ junit_version = ‘5.1.0’ junit_plugin_version = ‘1.1.0’
kotlin_test_version = ‘3.0.1’ } repositories { mavenCentral() } dependencies { classpath “org.springframework.boot:spring-boot-gradle-plugin:$spring_boot_version” classpath “org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version” classpath “org.jetbrains.kotlin:kotlin-allopen:$kotlin_version” classpath “org.jetbrains.kotlin:kotlin-noarg:$kotlin_version” classpath “org.junit.platform:junit-platform-gradle-plugin:$junit_plugin_version” } }

apply plugin: ‘org.springframework.boot’ apply plugin: ‘war’ apply plugin: ‘java’ apply plugin: ‘kotlin’ apply plugin: ‘kotlin-spring’ apply plugin: ‘kotlin-jpa’ apply plugin: ‘org.junit.platform.gradle.plugin’

sourceCompatibility = 1.8

repositories { mavenCentral() }

configurations { providedRuntime }

springBoot { buildInfo() }

dependencies { //Kotlin compile “org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version” compile “org.jetbrains.kotlin:kotlin-reflect:$kotlin_version”

//Load core spring-boot starters:
compile "org.springframework.boot:spring-boot-starter:$spring_boot_version"
compile "org.springframework:spring-web:$spring_version"

//Load data-access dependencies:
compile "org.springframework.boot:spring-boot-starter-data-jpa:$spring_boot_version"
runtime 'mysql:mysql-connector-java'

providedCompile "org.springframework.boot:spring-boot-starter-tomcat:$spring_boot_version"

//Load test dependencies
testCompile 'org.springframework:spring-context'
testCompile 'org.springframework:spring-test'
testCompile "org.springframework.boot:spring-boot-test:$spring_boot_version"

testCompile "org.junit.platform:junit-platform-launcher:$junit_plugin_version"
testCompile "org.junit.platform:junit-platform-runner:$junit_plugin_version"
testCompile "io.kotlintest:kotlintest-runner-junit5:$kotlin_test_version"
testCompile "io.kotlintest:kotlintest-extensions-spring:$kotlin_test_version"

}

compileKotlin { kotlinOptions.jvmTarget = java_version } compileTestKotlin { kotlinOptions.jvmTarget = java_version }

bootRun { systemProperties[“spring.profiles.active”] = System.properties[“spring.profiles.active”] ?: “development” }

test { useJUnitPlatform() systemProperties[“spring.profiles.active”] = System.properties[“spring.profiles.active”] ?: “test” testLogging { exceptionFormat = ‘full’ } }

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:33 (33 by maintainers)

github_iconTop GitHub Comments

1reaction
bondpp7commented, Apr 10, 2018

I found why the ‘active-profile’ wasn’t working. It’s nothing related to Kotlin-Test; when using Junit5 and spring-boot, JUnit5 w/ Gradle 4.6+ recommends using useJUnitPlatform() within the “test” task, rather than the (now obsolete) gradle-plugin. Doing this means that systemProperties["spring.profiles.active"] must be set within JUnit’s “junitPlatformTest” task, rather than the standard “test” task. That was the root issue.

0reactions
sksamuelcommented, Apr 10, 2018

Aha, well thanks for coming back and updating the ticket.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Gradle test task: not found - Stack Overflow
In Gradle doc, it said: Adds the standard lifecycle tasks and configures reasonable defaults for the archive tasks:.
Read more >
Can't run tests in Gradle project: "No tests were found" error
When I launch "cleanTest test" configuration: "Task events were not received". P.S.: By the way, there is a missing "\n" in Class not...
Read more >
Junit 5 test suites not running - Help/Discuss - Gradle Forums
I'm migrating my junit test cases from 4 to 5. In Junit 4 I have test suites. The new Junit 5 “test suites”...
Read more >
no tests for given includes: Gradle JUnit Kotlin Java Fixes
No tests found for given includesHere is 3 ways it can happen and how to fix.check that your build. gradle has a test...
Read more >
Gradle + JUnit: Not running @Test : r/javahelp - Reddit
When a execute ~$ gradle clean test my test class does not seem to fire. I'm not intimately familiar with how the Gradle/JUnit...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found