or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

build-chain-customization.mddev-mode-testing.mdindex.mdlogging-test-resources.mdprod-mode-testing.mdresults-utilities.mdunit-testing.md

prod-mode-testing.mddocs/

0

# Production Mode Testing

1

2

The `QuarkusProdModeTest` class provides testing capabilities for production-mode jars with native build support, runtime configuration, and process lifecycle management.

3

4

## Core API

5

6

### Basic Setup

7

8

```java { .api }

9

public class QuarkusProdModeTest implements BeforeAllCallback, AfterAllCallback,

10

BeforeEachCallback, TestWatcher, InvocationInterceptor {

11

12

public QuarkusProdModeTest();

13

}

14

```

15

16

### Archive Configuration

17

18

Configure the application archive:

19

20

```java { .api }

21

public Supplier<JavaArchive> getArchiveProducer();

22

public QuarkusProdModeTest setArchiveProducer(Supplier<JavaArchive> archiveProducer);

23

public QuarkusProdModeTest withApplicationRoot(Consumer<JavaArchive> applicationRootConsumer);

24

public QuarkusProdModeTest withEmptyApplication();

25

```

26

27

### Build Chain Customization

28

29

Add build chain customizers and custom resources:

30

31

```java { .api }

32

public QuarkusProdModeTest addBuildChainCustomizerEntries(BuildChainCustomizerEntry entry);

33

public QuarkusProdModeTest addCustomResourceEntry(Path outputPath, String classPathLocation);

34

```

35

36

### Application Configuration

37

38

Configure application metadata:

39

40

```java { .api }

41

public QuarkusProdModeTest setApplicationName(String applicationName);

42

public QuarkusProdModeTest setApplicationVersion(String applicationVersion);

43

```

44

45

### Build Configuration

46

47

Configure build options:

48

49

```java { .api }

50

public QuarkusProdModeTest setBuildNative(boolean buildNative);

51

public QuarkusProdModeTest setRun(boolean run);

52

```

53

54

### Runtime Configuration

55

56

Configure runtime behavior:

57

58

```java { .api }

59

public QuarkusProdModeTest setJVMArgs(List<String> jvmArgs);

60

public QuarkusProdModeTest setRuntimeProperties(Map<String, String> runtimeProperties);

61

```

62

63

### Logging Configuration

64

65

Configure logging behavior:

66

67

```java { .api }

68

public QuarkusProdModeTest setLogFileName(String logFileName);

69

public QuarkusProdModeTest setLogRecordPredicate(Predicate<LogRecord> predicate);

70

```

71

72

### Dependencies Management

73

74

Configure forced dependencies:

75

76

```java { .api }

77

public QuarkusProdModeTest setForcedDependencies(List<Dependency> forcedDependencies);

78

```

79

80

### Process Control

81

82

Control application process lifecycle:

83

84

```java { .api }

85

public QuarkusProdModeTest setExpectExit(boolean expectExit);

86

public void start();

87

public void stop();

88

```

89

90

### Exception Handling

91

92

Configure build and runtime exception handling:

93

94

```java { .api }

95

public QuarkusProdModeTest assertBuildException(Consumer<Throwable> exceptionAssert);

96

public QuarkusProdModeTest setExpectedException(Class<? extends Throwable> expectedException);

97

```

98

99

### Output Access

100

101

Access application output and exit status:

102

103

```java { .api }

104

public String getStartupConsoleOutput();

105

public Integer getExitCode();

106

```

107

108

### Configuration Management

109

110

Override configuration keys and provide resources:

111

112

```java { .api }

113

public QuarkusProdModeTest withConfigurationResource(String resourceName);

114

public QuarkusProdModeTest overrideConfigKey(String propertyKey, String propertyValue);

115

public QuarkusProdModeTest setCommandLineParameters(String... commandLineParameters);

116

```

117

118

## Nested Types

119

120

### BuildChainCustomizerEntry

121

122

```java { .api }

123

public static class BuildChainCustomizerEntry {

124

public BuildChainCustomizerEntry(Class<? extends ProdModeTestBuildStep> buildStepClass,

125

List<Class<? extends BuildItem>> produces, List<Class<? extends BuildItem>> consumes);

126

public Class<? extends BuildStep> getBuildStepClass();

127

public List<Class<? extends BuildItem>> getProduces();

128

public List<Class<? extends BuildItem>> getConsumes();

129

}

130

```

131

132

## Constants

133

134

```java { .api }

135

public static String BUILD_CONTEXT_CUSTOM_SOURCES_PATH_KEY = "customSourcesDir";

136

```

137

138

Key for custom sources directory in build context.

139

140

## Usage Examples

141

142

### Basic Production Mode Test

143

144

```java

145

import io.quarkus.test.QuarkusProdModeTest;

146

import org.jboss.shrinkwrap.api.ShrinkWrap;

147

import org.jboss.shrinkwrap.api.spec.JavaArchive;

148

import org.junit.jupiter.api.extension.RegisterExtension;

149

import org.junit.jupiter.api.Test;

150

151

public class ProdModeTest {

152

153

@RegisterExtension

154

static final QuarkusProdModeTest config = new QuarkusProdModeTest()

155

.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)

156

.addClasses(MyResource.class))

157

.setRun(true);

158

159

@Test

160

public void testProductionBuild() {

161

// Test production mode functionality

162

}

163

}

164

```

165

166

### Native Build Test

167

168

```java

169

@RegisterExtension

170

static final QuarkusProdModeTest config = new QuarkusProdModeTest()

171

.withApplicationRoot(jar -> jar.addClasses(MyResource.class))

172

.setBuildNative(true)

173

.setRun(true);

174

```

175

176

### Test with Runtime Configuration

177

178

```java

179

@RegisterExtension

180

static final QuarkusProdModeTest config = new QuarkusProdModeTest()

181

.withApplicationRoot(jar -> jar.addClasses(MyService.class))

182

.setRuntimeProperties(Map.of(

183

"quarkus.log.level", "DEBUG",

184

"app.environment", "test"

185

))

186

.setJVMArgs(List.of("-Xmx512m", "-Dfile.encoding=UTF-8"));

187

```

188

189

### Test with Build Chain Customization

190

191

```java

192

@RegisterExtension

193

static final QuarkusProdModeTest config = new QuarkusProdModeTest()

194

.withApplicationRoot(jar -> jar.addClasses(MyService.class))

195

.addBuildChainCustomizerEntries(new QuarkusProdModeTest.BuildChainCustomizerEntry(

196

MyBuildStep.class,

197

List.of(MyBuildItem.class),

198

List.of(ApplicationArchivesBuildItem.class)

199

));

200

201

public static class MyBuildStep extends ProdModeTestBuildStep {

202

public MyBuildStep(Map<String, Object> testContext) {

203

super(testContext);

204

}

205

206

@Override

207

public void execute(BuildContext context) {

208

// Custom build logic

209

}

210

}

211

```

212

213

### Test with Process Control

214

215

```java

216

@RegisterExtension

217

static final QuarkusProdModeTest config = new QuarkusProdModeTest()

218

.withApplicationRoot(jar -> jar.addClasses(MyService.class))

219

.setRun(false); // Build only, don't run

220

221

@Test

222

public void testBuildOnly() {

223

// Application is built but not started

224

// Can examine build artifacts, logs, etc.

225

}

226

227

@Test

228

public void testManualLifecycle() {

229

// Manual control over application lifecycle

230

config.start();

231

232

// Test running application

233

// ...

234

235

config.stop();

236

}

237

```

238

239

### Test with Exception Handling

240

241

```java

242

@RegisterExtension

243

static final QuarkusProdModeTest config = new QuarkusProdModeTest()

244

.withApplicationRoot(jar -> jar.addClasses(FailingService.class))

245

.assertBuildException(throwable -> {

246

assertTrue(throwable.getMessage().contains("Expected build failure"));

247

});

248

```

249

250

### Test with Exit Handling

251

252

```java

253

@RegisterExtension

254

static final QuarkusProdModeTest config = new QuarkusProdModeTest()

255

.withApplicationRoot(jar -> jar.addClasses(ExitingService.class))

256

.setExpectExit(true);

257

258

@Test

259

public void testApplicationExit() {

260

// Test applications that exit normally

261

int exitCode = config.getExitCode();

262

assertEquals(0, exitCode);

263

}

264

```

265

266

### Test with Console Output Verification

267

268

```java

269

@RegisterExtension

270

static final QuarkusProdModeTest config = new QuarkusProdModeTest()

271

.withApplicationRoot(jar -> jar.addClasses(LoggingService.class))

272

.setRun(true);

273

274

@Test

275

public void testConsoleOutput() {

276

String output = config.getStartupConsoleOutput();

277

assertTrue(output.contains("Application started successfully"));

278

}

279

```

280

281

### Test with Custom Resources

282

283

```java

284

@RegisterExtension

285

static final QuarkusProdModeTest config = new QuarkusProdModeTest()

286

.withApplicationRoot(jar -> jar.addClasses(MyService.class))

287

.addCustomResourceEntry(

288

Paths.get("target/custom-config"),

289

"META-INF/custom-config.yaml"

290

);

291

```

292

293

### Test with Configuration Override

294

295

```java

296

@RegisterExtension

297

static final QuarkusProdModeTest config = new QuarkusProdModeTest()

298

.withApplicationRoot(jar -> jar.addClasses(MyService.class))

299

.withConfigurationResource("prod-test-application.properties")

300

.overrideConfigKey("quarkus.http.port", "8081")

301

.setCommandLineParameters(new String[]{"--config", "custom.properties"});

302

```

303

304

### Test with Forced Dependencies

305

306

```java

307

@RegisterExtension

308

static final QuarkusProdModeTest config = new QuarkusProdModeTest()

309

.withApplicationRoot(jar -> jar.addClasses(MyService.class))

310

.setForcedDependencies(List.of(

311

Dependency.of("org.example", "test-extension", "1.0.0")

312

));

313

```