Skip to content

Commit 586c643

Browse files
authored
SONARGO-70 Add "integration-test" to common Gradle modules (#4)
1 parent 0f11890 commit 586c643

2 files changed

Lines changed: 92 additions & 0 deletions

File tree

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* SonarSource Cloud Native Gradle Modules
3+
* Copyright (C) 2024-2024 SonarSource SA
4+
* mailto:info AT sonarsource DOT com
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the Sonar Source-Available License Version 1, as published by SonarSource SA.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+
* See the Sonar Source-Available License for more details.
13+
*
14+
* You should have received a copy of the Sonar Source-Available License
15+
* along with this program; if not, see https://sonarsource.com/license/ssal/
16+
*/
17+
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
18+
import org.gradle.api.tasks.testing.logging.TestLogEvent.FAILED
19+
import org.gradle.api.tasks.testing.logging.TestLogEvent.PASSED
20+
import org.gradle.api.tasks.testing.logging.TestLogEvent.SKIPPED
21+
import org.gradle.api.tasks.testing.logging.TestLogEvent.STARTED
22+
import org.sonarsource.cloudnative.gradle.IntegrationTestExtension
23+
24+
// Inspiration: https://docs.gradle.org/current/samples/sample_jvm_multi_project_with_additional_test_types.html
25+
26+
plugins {
27+
java
28+
id("org.sonarsource.cloud-native.java-conventions")
29+
}
30+
31+
val integrationTest by sourceSets.creating
32+
val integrationTestConfiguration = extensions.create<IntegrationTestExtension>("integrationTest")
33+
34+
configurations[integrationTest.implementationConfigurationName].extendsFrom(configurations.testImplementation.get())
35+
configurations[integrationTest.runtimeOnlyConfigurationName].extendsFrom(configurations.testRuntimeOnly.get())
36+
37+
tasks.register<Test>("integrationTest") {
38+
description = "Runs integration tests."
39+
group = "verification"
40+
inputs.dir(integrationTestConfiguration.testSources)
41+
inputs.property("SQ version", System.getProperty("sonar.runtimeVersion", "LATEST_RELEASE"))
42+
inputs.property("keep SQ running", System.getProperty("keepSonarqubeRunning", "false"))
43+
useJUnitPlatform()
44+
45+
testClassesDirs = integrationTest.output.classesDirs
46+
classpath = configurations[integrationTest.runtimeClasspathConfigurationName] + integrationTest.output
47+
48+
if (System.getProperty("sonar.runtimeVersion") != null) {
49+
systemProperty("sonar.runtimeVersion", System.getProperty("sonar.runtimeVersion", "LATEST_RELEASE"))
50+
}
51+
52+
if (System.getProperty("keepSonarqubeRunning") != null) {
53+
systemProperty("keepSonarqubeRunning", System.getProperty("keepSonarqubeRunning"))
54+
}
55+
56+
testLogging {
57+
// log the full stack trace (default is the 1st line of the stack trace)
58+
exceptionFormat = TestExceptionFormat.FULL
59+
events(STARTED, PASSED, SKIPPED, FAILED)
60+
}
61+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.sonarsource.cloudnative.gradle
2+
3+
import groovy.lang.Closure
4+
import org.gradle.api.Project
5+
import org.gradle.api.file.DirectoryProperty
6+
import org.gradle.api.tasks.testing.Test
7+
import org.gradle.kotlin.dsl.named
8+
9+
interface IntegrationTestExtension {
10+
/**
11+
* The directory containing the source files for the integration tests.
12+
* Will be treated as a task input for the integration test task to check if the task is up-to-date.
13+
*/
14+
val testSources: DirectoryProperty
15+
16+
/**
17+
* Additional configuration for the integration test task.
18+
*/
19+
fun Project.configureTask(action: Test.() -> Unit) {
20+
tasks.named<Test>("integrationTest", action)
21+
}
22+
23+
/**
24+
* Additional configuration for the integration test task.
25+
*/
26+
fun Project.configureTask(action: Closure<*>) {
27+
tasks.named<Test>("integrationTest") {
28+
action.call(this)
29+
}
30+
}
31+
}

0 commit comments

Comments
 (0)