0
# Development Mode Testing
1
2
The `QuarkusDevModeTest` class provides black-box testing capabilities for Quarkus development mode, including file modification support, hot reload testing, and build system integration.
3
4
## Core API
5
6
### Basic Setup
7
8
```java { .api }
9
public class QuarkusDevModeTest implements BeforeAllCallback, AfterAllCallback,
10
BeforeEachCallback, AfterEachCallback, TestInstanceFactory {
11
12
public QuarkusDevModeTest();
13
}
14
```
15
16
### Archive Configuration
17
18
Configure the application and test archives:
19
20
```java { .api }
21
public Supplier<JavaArchive> getArchiveProducer();
22
public QuarkusDevModeTest setArchiveProducer(Supplier<JavaArchive> archiveProducer);
23
public QuarkusDevModeTest withApplicationRoot(Consumer<JavaArchive> applicationRootConsumer);
24
public QuarkusDevModeTest withEmptyApplication();
25
public QuarkusDevModeTest setTestArchiveProducer(Supplier<JavaArchive> testArchiveProducer);
26
public QuarkusDevModeTest withTestArchive(Consumer<JavaArchive> testArchiveConsumer);
27
```
28
29
### File Operations
30
31
Modify source and resource files during testing:
32
33
```java { .api }
34
public void modifySourceFile(String sourceFile, Function<String, String> mutator);
35
public void modifyFile(String file, Function<String, String> mutator);
36
public void modifySourceFile(Class<?> sourceFile, Function<String, String> mutator);
37
public void modifyTestSourceFile(Class<?> sourceFile, Function<String, String> mutator);
38
public void addSourceFile(Class<?> sourceFile);
39
public void modifyResourceFile(String path, Function<String, String> mutator);
40
public void modifyTestResourceFile(String path, Function<String, String> mutator);
41
public void addResourceFile(String path, String data);
42
public void addResourceFile(String path, byte[] data);
43
public void deleteResourceFile(String path);
44
```
45
46
### Code Generation
47
48
Configure code generation sources:
49
50
```java { .api }
51
public QuarkusDevModeTest setCodeGenSources(String... codeGenSources);
52
```
53
54
### Logging Configuration
55
56
Configure logging behavior:
57
58
```java { .api }
59
public QuarkusDevModeTest setLogFileName(String logFileName);
60
public QuarkusDevModeTest setLogRecordPredicate(Predicate<LogRecord> predicate);
61
public List<LogRecord> getLogRecords();
62
public void clearLogRecords();
63
```
64
65
### Build System Integration
66
67
Configure build system properties:
68
69
```java { .api }
70
public QuarkusDevModeTest setBuildSystemProperty(String name, String value);
71
```
72
73
### Command Line Configuration
74
75
Handle command line arguments:
76
77
```java { .api }
78
public String[] getCommandLineArgs();
79
public QuarkusDevModeTest setCommandLineArgs(String[] commandLineArgs);
80
```
81
82
### Error Handling
83
84
Configure failure handling behavior:
85
86
```java { .api }
87
public boolean isAllowFailedStart();
88
public QuarkusDevModeTest setAllowFailedStart(boolean allowFailedStart);
89
```
90
91
## Constants
92
93
```java { .api }
94
public static final OpenOption[] OPEN_OPTIONS;
95
```
96
97
Default file open options used for file operations.
98
99
## Usage Examples
100
101
### Basic Development Mode Test
102
103
```java
104
import io.quarkus.test.QuarkusDevModeTest;
105
import org.jboss.shrinkwrap.api.ShrinkWrap;
106
import org.jboss.shrinkwrap.api.spec.JavaArchive;
107
import org.junit.jupiter.api.extension.RegisterExtension;
108
import org.junit.jupiter.api.Test;
109
110
public class DevModeTest {
111
112
@RegisterExtension
113
static final QuarkusDevModeTest config = new QuarkusDevModeTest()
114
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
115
.addClasses(MyResource.class));
116
117
@Test
118
public void testHotReload() {
119
// Test hot reload functionality
120
}
121
}
122
```
123
124
### Test with File Modifications
125
126
```java
127
@RegisterExtension
128
static final QuarkusDevModeTest config = new QuarkusDevModeTest()
129
.withApplicationRoot(jar -> jar.addClasses(MyResource.class));
130
131
@Test
132
public void testFileModification() {
133
// Modify a source file and test hot reload
134
config.modifySourceFile("org/example/MyResource.java", source ->
135
source.replace("Hello World", "Hello Universe"));
136
137
// Test that changes are reflected
138
// ...
139
}
140
```
141
142
### Test with Resource File Changes
143
144
```java
145
@Test
146
public void testResourceModification() {
147
// Add a new resource file
148
config.addResourceFile("config/app.properties", "key=value");
149
150
// Modify existing resource
151
config.modifyResourceFile("application.properties", content ->
152
content + "\nnew.property=new-value");
153
154
// Test resource changes
155
// ...
156
}
157
```
158
159
### Test with Multiple Archive Types
160
161
```java
162
@RegisterExtension
163
static final QuarkusDevModeTest config = new QuarkusDevModeTest()
164
.withApplicationRoot(jar -> jar.addClasses(MyService.class))
165
.withTestArchive(testJar -> testJar.addClasses(TestResource.class));
166
```
167
168
### Test with Code Generation
169
170
```java
171
@RegisterExtension
172
static final QuarkusDevModeTest config = new QuarkusDevModeTest()
173
.withApplicationRoot(jar -> jar.addClasses(MyService.class))
174
.setCodeGenSources("src/main/proto", "src/main/avro");
175
```
176
177
### Test with Build System Properties
178
179
```java
180
@RegisterExtension
181
static final QuarkusDevModeTest config = new QuarkusDevModeTest()
182
.withApplicationRoot(jar -> jar.addClasses(MyService.class))
183
.setBuildSystemProperty("maven.compiler.source", "17")
184
.setBuildSystemProperty("maven.compiler.target", "17");
185
```
186
187
### Test with Command Line Arguments
188
189
```java
190
@RegisterExtension
191
static final QuarkusDevModeTest config = new QuarkusDevModeTest()
192
.withApplicationRoot(jar -> jar.addClasses(MyService.class))
193
.setCommandLineArgs(new String[]{"--debug", "--verbose"});
194
```
195
196
### Test with Logging Assertions
197
198
```java
199
@RegisterExtension
200
static final QuarkusDevModeTest config = new QuarkusDevModeTest()
201
.withApplicationRoot(jar -> jar.addClasses(MyService.class))
202
.setLogRecordPredicate(record -> record.getLevel() == Level.INFO);
203
204
@Test
205
public void testLogging() {
206
// Perform actions that generate logs
207
// ...
208
209
// Check logs
210
List<LogRecord> logs = config.getLogRecords();
211
assertTrue(logs.stream()
212
.anyMatch(record -> record.getMessage().contains("Expected message")));
213
214
// Clear logs for next test
215
config.clearLogRecords();
216
}
217
```
218
219
### Test with Failure Handling
220
221
```java
222
@RegisterExtension
223
static final QuarkusDevModeTest config = new QuarkusDevModeTest()
224
.withApplicationRoot(jar -> jar.addClasses(FailingService.class))
225
.setAllowFailedStart(true);
226
227
@Test
228
public void testFailureRecovery() {
229
// Test recovery from startup failures
230
// ...
231
}
232
```
233
234
## File Operation Patterns
235
236
### Simulating Code Changes
237
238
```java
239
// Modify method implementation
240
config.modifySourceFile("org/example/MyService.java", source ->
241
source.replace(
242
"public String getMessage() { return \"Hello\"; }",
243
"public String getMessage() { return \"Hello World\"; }"
244
));
245
246
// Add new method
247
config.modifySourceFile("org/example/MyService.java", source ->
248
source.replace(
249
"}\n$", // End of class
250
" public String getNewMessage() { return \"New\"; }\n}\n"
251
));
252
```
253
254
### Managing Configuration Files
255
256
```java
257
// Update application properties
258
config.modifyResourceFile("application.properties", props ->
259
props + "\nquarkus.log.level=DEBUG");
260
261
// Add new configuration file
262
config.addResourceFile("META-INF/microprofile-config.properties",
263
"app.name=Test Application\napp.version=1.0.0");
264
```