Skip to content

Commit 3aa2605

Browse files
committed
Replace TestSourcesPlugin with Gradle test fixture support
Prior to this series of commits, the Spring Framework build used a custom TestSourcesPlugin to share test utilities and fixtures between projects. This plugin served its purpose; however, it also had its drawbacks: - All test code was visible in all other (downstream) projects, and that made it too easy to introduce unnecessary coupling. For example, this made it more difficult to migrate to JUnit Jupiter. This commit addresses such issues by migrating to Gradle's first-class support for "Java test fixtures". - Having test fixture code in a dedicated source folder makes it readily apparent that the code is reused across the test suite. - The build is now much cleaner since projects explicitly declare that they rely on specific test fixtures of upstream projects. - Incremental builds are now much faster on average since downstream projects no longer have to be recompiled due to changes in tests in upstream projects. - Prior to these commits we effectively had around 20 test fixture dependencies. With these commits we effectively now have only 7 test fixture dependencies (i.e., projects that share test fixtures). Closes gh-23550
2 parents 75fd391 + d5f0bb2 commit 3aa2605

File tree

1,205 files changed

+4067
-3664
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,205 files changed

+4067
-3664
lines changed

build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ configure([rootProject] + javaProjects) { project ->
308308
group = "org.springframework"
309309

310310
apply plugin: "java"
311+
apply plugin: "java-test-fixtures"
311312
apply plugin: "checkstyle"
312313
apply plugin: 'org.springframework.build.compile'
313314
apply from: "${rootDir}/gradle/ide.gradle"

buildSrc/README.md

+5-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Spring Framework build
1+
# Spring Framework Build
22

33
This folder contains the custom plugins and conventions for the Spring Framework build.
44
They are declared in the `build.gradle` file in this folder.
@@ -7,8 +7,8 @@ They are declared in the `build.gradle` file in this folder.
77

88
### Compiler conventions
99

10-
The `org.springframework.build.compile` applies the Java compiler conventions to the build.
11-
By default, the build is compiling sources with the `1.8` source and target compatibility.
10+
The `org.springframework.build.compile` plubin applies the Java compiler conventions to the build.
11+
By default, the build compiles sources with Java `1.8` source and target compatibility.
1212
You can test a different source compatibility version on the CLI with a project property like:
1313

1414
```
@@ -25,17 +25,11 @@ but doesn't affect the classpath of dependent projects.
2525
This plugin does not provide a `provided` configuration, as the native `compileOnly` and `testCompileOnly`
2626
configurations are preferred.
2727

28-
## Test sources
29-
30-
The `org.springframework.build.test-sources` updates `testCompile` dependencies to include
31-
the test source sets of `project()` dependencies. This plugin is used in the Spring Framework build
32-
to share test utilities and fixtures amongst modules.
33-
3428
## API Diff
3529

3630
This plugin uses the [Gradle JApiCmp](https://github.com/melix/japicmp-gradle-plugin) plugin
3731
to generate API Diff reports for each Spring Framework module. This plugin is applied once on the root
38-
project and create tasks in each framework module. Unlike previous versions of this part of the build,
32+
project and creates tasks in each framework module. Unlike previous versions of this part of the build,
3933
there is no need for checking out a specific tag. The plugin will fetch the JARs we want to compare the
4034
current working version with. You can generate the reports for all modules or a single module:
4135

@@ -44,4 +38,4 @@ current working version with. You can generate the reports for all modules or a
4438
./gradlew :spring-core:apiDiff -PbaselineVersion=5.1.0.RELEASE
4539
```
4640

47-
The reports are located under `build/reports/api-diff/$OLDVERSION_to_$NEWVERSION/`.
41+
The reports are located under `build/reports/api-diff/$OLDVERSION_to_$NEWVERSION/`.

buildSrc/build.gradle

-4
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,5 @@ gradlePlugin {
2626
id = "org.springframework.build.optional-dependencies"
2727
implementationClass = "org.springframework.build.optional.OptionalDependenciesPlugin"
2828
}
29-
testSourcesPlugin {
30-
id = "org.springframework.build.test-sources"
31-
implementationClass = "org.springframework.build.testsources.TestSourcesPlugin"
32-
}
3329
}
3430
}

buildSrc/src/main/java/org/springframework/build/testsources/TestSourcesPlugin.java

-95
This file was deleted.

gradle/spring-module.gradle

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
apply plugin: 'org.springframework.build.compile'
22
apply plugin: 'org.springframework.build.optional-dependencies'
3-
apply plugin: 'org.springframework.build.test-sources'
43
apply from: "$rootDir/gradle/publications.gradle"
54

65
jar {
@@ -56,6 +55,14 @@ task javadocJar(type: Jar) {
5655
publishing {
5756
publications {
5857
mavenJava(MavenPublication) {
58+
// Disable publication of test fixture artifacts.
59+
//
60+
// Once we upgrade to Gradle 6.x, we will need to delete the following line ...
61+
components.java.variants.removeAll { it.outgoingConfiguration.name.startsWith("testFixtures") }
62+
// ... and uncomment the following two lines.
63+
// components.java.withVariantsFromConfiguration(configurations.testFixturesApiElements) { skip() }
64+
// components.java.withVariantsFromConfiguration(configurations.testFixturesRuntimeElements) { skip() }
65+
5966
from components.java
6067
artifact sourcesJar
6168
artifact javadocJar

integration-tests/integration-tests.gradle

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
description = "Spring Integration Tests"
22

3-
apply plugin: "org.springframework.build.test-sources"
4-
53
dependencies {
64
testCompile(project(":spring-aop"))
75
testCompile(project(":spring-beans"))
86
testCompile(project(":spring-context"))
97
testCompile(project(":spring-core"))
8+
testCompile(testFixtures(project(":spring-aop")))
9+
testCompile(testFixtures(project(":spring-beans")))
10+
testCompile(testFixtures(project(":spring-core")))
11+
testCompile(testFixtures(project(":spring-tx")))
1012
testCompile(project(":spring-expression"))
1113
testCompile(project(":spring-jdbc"))
1214
testCompile(project(":spring-orm"))

integration-tests/src/test/java/org/springframework/aop/config/AopNamespaceHandlerScopeIntegrationTests.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
import org.springframework.aop.framework.Advised;
2222
import org.springframework.aop.support.AopUtils;
2323
import org.springframework.beans.factory.annotation.Autowired;
24+
import org.springframework.beans.testfixture.beans.ITestBean;
25+
import org.springframework.beans.testfixture.beans.TestBean;
26+
import org.springframework.core.testfixture.io.SerializationTestUtils;
2427
import org.springframework.mock.web.MockHttpServletRequest;
2528
import org.springframework.mock.web.MockHttpSession;
2629
import org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig;
27-
import org.springframework.tests.sample.beans.ITestBean;
28-
import org.springframework.tests.sample.beans.TestBean;
29-
import org.springframework.util.SerializationTestUtils;
3030
import org.springframework.web.context.request.RequestContextHolder;
3131
import org.springframework.web.context.request.ServletRequestAttributes;
3232

integration-tests/src/test/java/org/springframework/aop/framework/autoproxy/AdvisorAutoProxyCreatorIntegrationTests.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@
2626

2727
import org.springframework.aop.support.AopUtils;
2828
import org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor;
29+
import org.springframework.aop.testfixture.advice.CountingBeforeAdvice;
30+
import org.springframework.aop.testfixture.advice.MethodCounter;
31+
import org.springframework.aop.testfixture.interceptor.NopInterceptor;
2932
import org.springframework.beans.factory.BeanFactory;
3033
import org.springframework.beans.factory.InitializingBean;
34+
import org.springframework.beans.testfixture.beans.ITestBean;
3135
import org.springframework.context.support.ClassPathXmlApplicationContext;
3236
import org.springframework.lang.Nullable;
33-
import org.springframework.tests.aop.advice.CountingBeforeAdvice;
34-
import org.springframework.tests.aop.advice.MethodCounter;
35-
import org.springframework.tests.aop.interceptor.NopInterceptor;
36-
import org.springframework.tests.sample.beans.ITestBean;
37-
import org.springframework.tests.transaction.CallCountingTransactionManager;
3837
import org.springframework.transaction.NoTransactionException;
3938
import org.springframework.transaction.interceptor.TransactionInterceptor;
39+
import org.springframework.transaction.testfixture.CallCountingTransactionManager;
4040

4141
import static org.assertj.core.api.Assertions.assertThat;
4242

integration-tests/src/test/java/org/springframework/scheduling/annotation/ScheduledAndTransactionalAnnotationIntegrationTests.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@
2828
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
2929
import org.springframework.context.annotation.Bean;
3030
import org.springframework.context.annotation.Configuration;
31+
import org.springframework.core.testfixture.EnabledForTestGroups;
3132
import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
3233
import org.springframework.dao.support.PersistenceExceptionTranslator;
3334
import org.springframework.stereotype.Repository;
34-
import org.springframework.tests.EnabledForTestGroups;
35-
import org.springframework.tests.transaction.CallCountingTransactionManager;
3635
import org.springframework.transaction.PlatformTransactionManager;
3736
import org.springframework.transaction.annotation.EnableTransactionManagement;
3837
import org.springframework.transaction.annotation.Transactional;
38+
import org.springframework.transaction.testfixture.CallCountingTransactionManager;
3939

4040
import static org.assertj.core.api.Assertions.assertThat;
4141
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
4242
import static org.mockito.Mockito.mock;
43-
import static org.springframework.tests.TestGroup.PERFORMANCE;
43+
import static org.springframework.core.testfixture.TestGroup.PERFORMANCE;
4444

4545
/**
4646
* Integration tests cornering bug SPR-8651, which revealed that @Scheduled methods may

integration-tests/src/test/java/org/springframework/transaction/annotation/EnableTransactionManagementIntegrationTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
4141
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
4242
import org.springframework.stereotype.Repository;
43-
import org.springframework.tests.transaction.CallCountingTransactionManager;
4443
import org.springframework.transaction.PlatformTransactionManager;
4544
import org.springframework.transaction.interceptor.BeanFactoryTransactionAttributeSourceAdvisor;
45+
import org.springframework.transaction.testfixture.CallCountingTransactionManager;
4646

4747
import static org.assertj.core.api.Assertions.assertThat;
4848
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

integration-tests/src/test/resources/org/springframework/aop/config/AopNamespaceHandlerScopeIntegrationTests-context.xml

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@
1111

1212
<bean id="advice" class="org.springframework.aop.interceptor.DebugInterceptor"/>
1313

14-
<bean id="testBean" class="org.springframework.tests.sample.beans.TestBean"/>
14+
<bean id="testBean" class="org.springframework.beans.testfixture.beans.TestBean"/>
1515

16-
<bean id="singletonScoped" class="org.springframework.tests.sample.beans.TestBean">
16+
<bean id="singletonScoped" class="org.springframework.beans.testfixture.beans.TestBean">
1717
<aop:scoped-proxy/>
1818
<property name="name" value="Rob Harrop"/>
1919
</bean>
2020

21-
<bean id="requestScoped" class="org.springframework.tests.sample.beans.TestBean" scope="request">
21+
<bean id="requestScoped" class="org.springframework.beans.testfixture.beans.TestBean" scope="request">
2222
<aop:scoped-proxy/>
2323
<property name="name" value="Rob Harrop"/>
2424
</bean>
2525

26-
<bean id="sessionScoped" name="sessionScopedAlias" class="org.springframework.tests.sample.beans.TestBean" scope="session">
26+
<bean id="sessionScoped" name="sessionScopedAlias" class="org.springframework.beans.testfixture.beans.TestBean" scope="session">
2727
<aop:scoped-proxy proxy-target-class="false"/>
2828
<property name="name" value="Rob Harrop"/>
2929
</bean>

integration-tests/src/test/resources/org/springframework/aop/framework/autoproxy/AdvisorAutoProxyCreatorIntegrationTests-context.xml

+7-7
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
</bean>
3535

3636
<!-- Often we can leave the definition of such infrastructural beans to child factories -->
37-
<bean id="txManager" class="org.springframework.tests.transaction.CallCountingTransactionManager"/>
37+
<bean id="txManager" class="org.springframework.transaction.testfixture.CallCountingTransactionManager"/>
3838

3939
<bean id="tas" class="org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource">
4040
<property name="properties">
@@ -74,20 +74,20 @@
7474

7575
<!-- These two beans would otherwise be eligible for autoproxying -->
7676

77-
<bean id="singletonDependency" class="org.springframework.tests.sample.beans.TestBean" scope="singleton"/>
77+
<bean id="singletonDependency" class="org.springframework.beans.testfixture.beans.TestBean" scope="singleton"/>
7878

79-
<bean id="prototypeDependency" class="org.springframework.tests.sample.beans.TestBean" scope="prototype"/>
79+
<bean id="prototypeDependency" class="org.springframework.beans.testfixture.beans.TestBean" scope="prototype"/>
8080

8181
<!-- ====== End test for prototype definitions to try to provoke circular references ========================= -->
8282

8383
<bean class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
8484
<property name="advice"><ref bean="countingAdvice"/></property>
85-
<property name="pattern"><value>org.springframework.tests.sample.beans.ITestBean.getName</value></property>
85+
<property name="pattern"><value>org.springframework.beans.testfixture.beans.ITestBean.getName</value></property>
8686
</bean>
8787

88-
<bean id="countingAdvice" class="org.springframework.tests.aop.advice.CountingAfterReturningAdvice"/>
88+
<bean id="countingAdvice" class="org.springframework.aop.testfixture.advice.CountingAfterReturningAdvice"/>
8989

90-
<bean id="test" class="org.springframework.tests.sample.beans.TestBean">
90+
<bean id="test" class="org.springframework.beans.testfixture.beans.TestBean">
9191
<property name="age"><value>4</value></property>
9292
</bean>
9393

@@ -97,7 +97,7 @@
9797

9898
<!-- The following beans test whether auto-proxying falls over for a null value -->
9999

100-
<bean id="tb" class="org.springframework.tests.sample.beans.TestBean"/>
100+
<bean id="tb" class="org.springframework.beans.testfixture.beans.TestBean"/>
101101

102102
<bean id="nullValueReturned" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
103103
<property name="targetObject" ref="tb"/>

spring-aop/spring-aop.gradle

+3
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ dependencies {
66
optional("org.aspectj:aspectjweaver")
77
optional("org.apache.commons:commons-pool2")
88
optional("com.jamonapi:jamon")
9+
testCompile(testFixtures(project(":spring-beans")))
10+
testCompile(testFixtures(project(":spring-core")))
11+
testFixturesImplementation(testFixtures(project(":spring-core")))
912
}

0 commit comments

Comments
 (0)