Skip to content

Commit

Permalink
chore: use testFixtures sourceset instead of depending on all the tes…
Browse files Browse the repository at this point in the history
…t classes

This change enables cleaner separation between "actual tests" and "support classes for the tests".

For instance, `:src:core` might provide dummy samplers like `ThreadSleep` for testing purposes.
`ThreadSleep` would depend on `src/test/main` (since it would `extend AbstractSampler`),
 and other modules (e.g. tests in `:src:protocols:http`) might need that `ThreadSleep` sampler.

It won't be practical to create `core-testkit` modules for every module,
so we move those reusable test classes to `testFixtures/...` source set.

See https://docs.gradle.org/current/userguide/java_testing.html#sec:java_test_fixtures
  • Loading branch information
vlsi committed Jun 8, 2023
1 parent f4d312c commit cabc3fb
Show file tree
Hide file tree
Showing 38 changed files with 42 additions and 45 deletions.
4 changes: 4 additions & 0 deletions build-logic/build-parameters/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ buildParameters {
defaultValue.set(true)
description.set("Skip forbidden-apis verifications")
}
bool("suppressPomMetadataWarnings") {
defaultValue.set(true)
description.set("Skip suppressPomMetadataWarningsFor warnings triggered by inability to map test fixtures dependences to Maven pom.xml")
}
bool("enableErrorprone") {
// By default, disable errorProne in CI so we don't perform the same checks in several jobs
defaultValue.set(System.getenv("CI") != "true")
Expand Down
22 changes: 3 additions & 19 deletions build-logic/jvm/src/main/kotlin/build-logic.java.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ dependencies {
}
findProject(":src:bom-testing")?.let{
testImplementation(platform(it))
plugins.withId("java-test-fixtures") {
"testFixturesImplementation"(platform(it))
}
}
findProject(":src:bom-thirdparty")?.let{
api(platform(it))
Expand Down Expand Up @@ -149,22 +152,3 @@ tasks.configureEach<Jar> {
attributes["Implementation-Version"] = rootProject.version
}
}

// <editor-fold defaultstate="collapsed" desc="TODO: remove dependencies between testClasses of the different projects">
val testClasses by configurations.creating {
}

if (file("src/test").isDirectory) {
// Do not generate test jars when src/test folder is missing (e.g. "config.jar")
val testJar by tasks.registering(Jar::class) {
val sourceSets: SourceSetContainer by project
archiveClassifier.set("test")
from(sourceSets["test"].output)
}

// Parenthesis needed to use Project#getArtifacts
(artifacts) {
testClasses(testJar)
}
}
// </editor-fold>
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@

plugins {
id("maven-publish")
id("build-logic.build-params")
id("build-logic.publish-to-tmp-maven-repo")
}

val repoUrl = "https://github.com/apache/jmeter"

publishing {
publications.withType<MavenPublication>().configureEach {
if (buildParameters.suppressPomMetadataWarnings) {
suppressPomMetadataWarningsFor("testFixturesApiElements")
suppressPomMetadataWarningsFor("testFixturesRuntimeElements")
}
// Use the resolved versions in pom.xml
// Gradle might have different resolution rules, so we set the versions
// that were used in Gradle build/test.
Expand Down
2 changes: 1 addition & 1 deletion src/components/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ plugins {

dependencies {
api(projects.src.core)
testImplementation(project(":src:core", "testClasses"))
testImplementation(testFixtures(projects.src.core))

api("org.apache-extras.beanshell:bsh") {
because(
Expand Down
9 changes: 8 additions & 1 deletion src/core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ import com.github.autostyle.gradle.AutostyleTask
import com.github.vlsi.gradle.ide.IdeExtension

plugins {
id("java-test-fixtures")
id("build-logic.jvm-published-library")
}

dependencies {
api(projects.src.launcher)
api(projects.src.jorphan)
testImplementation(project(":src:jorphan", "testClasses"))
testImplementation(testFixtures(projects.src.jorphan))

api("bsf:bsf") {
because("protected BSFManager BSFTestElement#getManager()")
Expand Down Expand Up @@ -120,6 +121,12 @@ dependencies {

testImplementation("commons-net:commons-net")
testRuntimeOnly("org.spockframework:spock-core")

testFixturesApi(testFixtures(projects.src.jorphan))
testFixturesImplementation("junit:junit")
testFixturesImplementation("org.spockframework:spock-core")
testFixturesImplementation(projects.src.testkit)
testFixturesImplementation("org.junit.jupiter:junit-jupiter")
}

val generatedVersionDir = File(buildDir, "generated/sources/version")
Expand Down
File renamed without changes.
4 changes: 3 additions & 1 deletion src/dist-check/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.apache.jmeter.buildtools.batchtest.BatchTestServer
import java.time.Duration

plugins {
id("java-test-fixtures")
id("build-logic.batchtest")
id("com.github.vlsi.gradle-extensions")
id("build-logic.jvm-library")
Expand All @@ -31,7 +32,8 @@ val loggingClasspath by configurations.creating

dependencies {
api(projects.src.dist)
testImplementation(project(":src:dist", "allTestClasses"))

testImplementation(testFixtures(projects.src.core))
testImplementation("org.apache.commons:commons-lang3") {
because("StringUtils")
}
Expand Down
6 changes: 0 additions & 6 deletions src/dist/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,11 @@ val srcLicense by configurations.creating {
isCanBeConsumed = false
}

val allTestClasses by configurations.creating {
isCanBeConsumed = true
isCanBeResolved = false
}

// Note: you can inspect final classpath (list of jars in the binary distribution) via
// gw dependencies --configuration runtimeClasspath
dependencies {
for (p in jars) {
api(project(p))
allTestClasses(project(p, "testClasses"))
}

binLicense(project(":src:licenses", "binLicense"))
Expand Down
2 changes: 1 addition & 1 deletion src/functions/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ plugins {

dependencies {
api(projects.src.components)
testImplementation(project(":src:core", "testClasses"))
testImplementation(testFixtures(projects.src.core))

implementation("org.mozilla:rhino")
implementation("commons-codec:commons-codec")
Expand Down
3 changes: 3 additions & 0 deletions src/jorphan/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

plugins {
id("java-test-fixtures")
id("build-logic.jvm-published-library")
}

Expand All @@ -28,4 +29,6 @@ dependencies {
implementation("org.apache.commons:commons-lang3")
implementation("org.apache.commons:commons-math3")
implementation("org.apache.commons:commons-text")

testFixturesImplementation("org.junit.jupiter:junit-jupiter")
}
2 changes: 1 addition & 1 deletion src/protocol/bolt/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ dependencies {
implementation("com.fasterxml.jackson.core:jackson-core")
implementation("com.fasterxml.jackson.core:jackson-databind")

testImplementation(project(":src:core", "testClasses"))
testImplementation(testFixtures(projects.src.core))
}
2 changes: 1 addition & 1 deletion src/protocol/ftp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ dependencies {
because("StringUtils")
}

testImplementation(project(":src:core", "testClasses"))
testImplementation(testFixtures(projects.src.core))
}
4 changes: 1 addition & 3 deletions src/protocol/http/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ dependencies {
api(projects.src.components) {
because("we need SearchTextExtension")
}
testImplementation(project(":src:components", "testClasses"))

api("com.thoughtworks.xstream:xstream") {
because("HTTPResultConverter uses XStream in public API")
Expand Down Expand Up @@ -77,6 +76,7 @@ dependencies {
implementation("com.miglayout:miglayout-swing")
implementation("com.fasterxml.jackson.core:jackson-core")
implementation("com.fasterxml.jackson.core:jackson-databind")
testImplementation(testFixtures(projects.src.core))
testImplementation(testFixtures(projects.src.testkitWiremock))
testImplementation("com.github.tomakehurst:wiremock-jre8")
// For some reason JMeter bundles just tika-core and tika-parsers without transitive
Expand All @@ -87,6 +87,4 @@ dependencies {
runtimeOnly("org.apache.tika:tika-parsers") {
isTransitive = false
}

testImplementation(project(":src:core", "testClasses"))
}
2 changes: 1 addition & 1 deletion src/protocol/java/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies {
because("IOUtils")
}

testImplementation(project(":src:core", "testClasses"))
testImplementation(testFixtures(projects.src.core))
testImplementation(projects.src.functions) {
because("We need __counter function for tests")
}
Expand Down
2 changes: 1 addition & 1 deletion src/protocol/jdbc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ dependencies {
because("IOUtils")
}

testImplementation(project(":src:core", "testClasses"))
testImplementation(testFixtures(projects.src.core))
}
3 changes: 1 addition & 2 deletions src/protocol/jms/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ plugins {
dependencies {
api(projects.src.core)

testImplementation(project(":src:core", "testClasses"))
api("com.github.ben-manes.caffeine:caffeine") {
because("MessageRenderer#getValueFromFile(..., caffeine.cache.Cache)")
}
Expand All @@ -37,5 +36,5 @@ dependencies {
}
implementation("com.miglayout:miglayout-swing")

testImplementation(project(":src:core", "testClasses"))
testImplementation(testFixtures(projects.src.core))
}
2 changes: 1 addition & 1 deletion src/protocol/junit-sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ dependencies {

api("junit:junit")

testImplementation(project(":src:core", "testClasses"))
testImplementation(testFixtures(projects.src.core))
}
2 changes: 1 addition & 1 deletion src/protocol/junit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ dependencies {
}
implementation("com.miglayout:miglayout-swing")

testImplementation(project(":src:core", "testClasses"))
testImplementation(testFixtures(projects.src.core))
}
2 changes: 1 addition & 1 deletion src/protocol/ldap/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ dependencies {
because("StringUtils")
}

testImplementation(project(":src:core", "testClasses"))
testImplementation(testFixtures(projects.src.core))
}
2 changes: 1 addition & 1 deletion src/protocol/mail/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ dependencies {
because("IOUtils")
}

testImplementation(project(":src:core", "testClasses"))
testImplementation(testFixtures(projects.src.core))
}
2 changes: 1 addition & 1 deletion src/protocol/mongodb/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ dependencies {
because("StringUtils")
}

testImplementation(project(":src:core", "testClasses"))
testImplementation(testFixtures(projects.src.core))
}
2 changes: 1 addition & 1 deletion src/protocol/native/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ dependencies {
because("StringUtils")
}

testImplementation(project(":src:core", "testClasses"))
testImplementation(testFixtures(projects.src.core))
}
2 changes: 1 addition & 1 deletion src/protocol/tcp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ dependencies {
because("IOUtils")
}

testImplementation(project(":src:core", "testClasses"))
testImplementation(testFixtures(projects.src.core))
}
1 change: 1 addition & 0 deletions xdocs/usermanual/jmeter_tutorial.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ The folders inside of <code>apache-jmeter</code>
<dt><code>lib/ext</code></dt><dd>contains the core jar files for JMeter and the protocols</dd>
<dt><code>src</code></dt><dd>contains subdirectory for each protocol and component</dd>
<dt><code>src/*/test</code></dt><dd>unit test related directory</dd>
<dt><code>src/testFixtures</code></dt><dd>Directory that contains test-related code that might be reused in other modules</dd>
<dt><code>xdocs</code></dt><dd>XML files for documentation. JMeter generates its documentation from XML.</dd>
</dl>

Expand Down

0 comments on commit cabc3fb

Please sign in to comment.