@@ -86,6 +86,20 @@ a Java properties file:
86
86
* `key:value`
87
87
* `key value`
88
88
89
+ [TIP]
90
+ ====
91
+ Although properties can be defined using any of the above syntax variants and any number
92
+ of spaces between the key and the value, it is recommended that you use one syntax
93
+ variant and consistent spacing within your test suite — for example, consider always
94
+ using `key = value` instead of `key= value`, `key=value`, etc. Similarly, if you define
95
+ inlined properties using text blocks you should consistently use text blocks for inlined
96
+ properties throughout your test suite.
97
+
98
+ The reason is that the exact strings you provide will be used to determine the key for
99
+ the context cache. Consequently, to benefit from the context cache you must ensure that
100
+ you define inlined properties consistently.
101
+ ====
102
+
89
103
The following example sets two inlined properties:
90
104
91
105
[tabs]
@@ -95,24 +109,61 @@ Java::
95
109
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
96
110
----
97
111
@ContextConfiguration
98
- @TestPropertySource(properties = {"timezone = GMT", "port: 4242"}) // <1>
112
+ @TestPropertySource(properties = {"timezone = GMT", "port = 4242"}) // <1>
113
+ class MyIntegrationTests {
114
+ // class body...
115
+ }
116
+ ----
117
+ <1> Setting two properties via an array of strings.
118
+
119
+ Kotlin::
120
+ +
121
+ [source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
122
+ ----
123
+ @ContextConfiguration
124
+ @TestPropertySource(properties = ["timezone = GMT", "port = 4242"]) // <1>
125
+ class MyIntegrationTests {
126
+ // class body...
127
+ }
128
+ ----
129
+ <1> Setting two properties via an array of strings.
130
+ ======
131
+
132
+ As of Spring Framework 6.1, you can use _text blocks_ to define multiple inlined
133
+ properties in a single `String`. The following example sets two inlined properties using
134
+ a text block:
135
+
136
+ [tabs]
137
+ ======
138
+ Java::
139
+ +
140
+ [source,java,indent=0,subs="verbatim,quotes",role="primary"]
141
+ ----
142
+ @ContextConfiguration
143
+ @TestPropertySource(properties = """
144
+ timezone = GMT
145
+ port = 4242
146
+ """) // <1>
99
147
class MyIntegrationTests {
100
148
// class body...
101
149
}
102
150
----
103
- <1> Setting two properties by using two variations of the key-value syntax .
151
+ <1> Setting two properties via a text block .
104
152
105
153
Kotlin::
106
154
+
107
155
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
108
156
----
109
157
@ContextConfiguration
110
- @TestPropertySource(properties = ["timezone = GMT", "port: 4242"]) // <1>
158
+ @TestPropertySource(properties = ["""
159
+ timezone = GMT
160
+ port = 4242
161
+ """]) // <1>
111
162
class MyIntegrationTests {
112
163
// class body...
113
164
}
114
165
----
115
- <1> Setting two properties by using two variations of the key-value syntax .
166
+ <1> Setting two properties via a text block .
116
167
======
117
168
118
169
[NOTE]
@@ -172,7 +223,7 @@ Java::
172
223
@ContextConfiguration
173
224
@TestPropertySource(
174
225
locations = "/test.properties",
175
- properties = {"timezone = GMT", "port: 4242"}
226
+ properties = {"timezone = GMT", "port = 4242"}
176
227
)
177
228
class MyIntegrationTests {
178
229
// class body...
@@ -185,7 +236,7 @@ Kotlin::
185
236
----
186
237
@ContextConfiguration
187
238
@TestPropertySource("/test.properties",
188
- properties = ["timezone = GMT", "port: 4242"]
239
+ properties = ["timezone = GMT", "port = 4242"]
189
240
)
190
241
class MyIntegrationTests {
191
242
// class body...
0 commit comments