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

results-utilities.mddocs/

0

# Result Containers and Utilities

1

2

Data containers and utility classes for managing test results, continuous testing support, and cache management.

3

4

## ProdModeTestResults

5

6

Container for production mode test build results.

7

8

### Core API

9

10

```java { .api }

11

public class ProdModeTestResults {

12

13

public ProdModeTestResults(Path buildDir, Path builtArtifactPath,

14

List<ArtifactResult> results, List<LogRecord> retainedBuildLogRecords);

15

16

public Path getBuildDir();

17

public Path getBuiltArtifactPath();

18

public List<ArtifactResult> getResults();

19

public List<LogRecord> getRetainedBuildLogRecords();

20

}

21

```

22

23

## ContinuousTestingTestUtils

24

25

Utilities for testing continuous testing functionality.

26

27

### Core API

28

29

```java { .api }

30

public class ContinuousTestingTestUtils {

31

32

public TestStatus waitForNextCompletion();

33

public static String appProperties(String... props);

34

}

35

```

36

37

### Nested Types

38

39

```java { .api }

40

public static class TestStatus {

41

public TestStatus();

42

public TestStatus(long lastRun, long running, long testsRun, long testsPassed,

43

long testsFailed, long testsSkipped, long totalTestsPassed,

44

long totalTestsFailed, long totalTestsSkipped);

45

46

// Status properties

47

public long getLastRun();

48

public void setLastRun(long lastRun);

49

public long getRunning();

50

public void setRunning(long running);

51

public long getTestsRun();

52

public void setTestsRun(long testsRun);

53

public long getTestsPassed();

54

public void setTestsPassed(long testsPassed);

55

public long getTestsFailed();

56

public void setTestsFailed(long testsFailed);

57

public long getTestsSkipped();

58

public void setTestsSkipped(long testsSkipped);

59

public long getTotalTestsPassed();

60

public void setTotalTestsPassed(long totalTestsPassed);

61

public long getTotalTestsFailed();

62

public void setTotalTestsFailed(long totalTestsFailed);

63

public long getTotalTestsSkipped();

64

public void setTotalTestsSkipped(long totalTestsSkipped);

65

66

public String toString();

67

}

68

```

69

70

## ExclusivityChecker

71

72

Ensures different test types don't run concurrently.

73

74

### Core API

75

76

```java { .api }

77

public class ExclusivityChecker {

78

79

public static void checkTestType(ExtensionContext extensionContext, Class<?> current);

80

}

81

```

82

83

### Constants

84

85

## ExclusivityChecker

86

87

Ensures different test types don't run concurrently.

88

89

### Core API

90

91

```java { .api }

92

public class ExclusivityChecker {

93

94

public static void checkTestType(ExtensionContext extensionContext, Class<?> current);

95

}

96

```

97

98

### Constants

99

100

```java { .api }

101

public static final String IO_QUARKUS_TESTING_TYPE = "io.quarkus.testing.type";

102

```

103

104

## ClearCache

105

106

Utility for clearing various internal caches.

107

108

### Core API

109

110

```java { .api }

111

public class ClearCache {

112

113

public static void clearCaches();

114

}

115

```

116

117

## Usage Examples

118

119

### Working with Production Build Results

120

121

```java

122

import io.quarkus.test.ProdBuildResults;

123

import io.quarkus.test.ProdModeTestResults;

124

import io.quarkus.test.QuarkusProdModeTest;

125

import org.junit.jupiter.api.Test;

126

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

127

128

public class BuildResultsTest {

129

130

@RegisterExtension

131

static final QuarkusProdModeTest config = new QuarkusProdModeTest()

132

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

133

.setRun(false); // Build only

134

135

@ProdBuildResults

136

ProdModeTestResults buildResults;

137

138

@Test

139

public void testBuildResults() {

140

// Access build directory

141

Path buildDir = buildResults.getBuildDir();

142

assertTrue(Files.exists(buildDir));

143

144

// Access built artifact

145

Path artifact = buildResults.getBuiltArtifactPath();

146

assertTrue(Files.exists(artifact));

147

assertTrue(artifact.toString().endsWith(".jar"));

148

149

// Examine build artifacts

150

List<ArtifactResult> results = buildResults.getResults();

151

assertFalse(results.isEmpty());

152

153

// Check build logs

154

List<LogRecord> buildLogs = buildResults.getRetainedBuildLogRecords();

155

assertTrue(buildLogs.stream()

156

.anyMatch(log -> log.getMessage().contains("BUILD SUCCESS")));

157

}

158

159

@Test

160

public void testArtifactContents() {

161

Path artifact = buildResults.getBuiltArtifactPath();

162

163

// Examine JAR contents

164

try (JarFile jarFile = new JarFile(artifact.toFile())) {

165

// Verify main class

166

Manifest manifest = jarFile.getManifest();

167

String mainClass = manifest.getMainAttributes().getValue("Main-Class");

168

assertNotNull(mainClass);

169

170

// Verify application classes are present

171

assertNotNull(jarFile.getEntry("org/example/MyService.class"));

172

173

// Verify dependencies are included

174

assertNotNull(jarFile.getEntry("META-INF/quarkus/"));

175

176

} catch (IOException e) {

177

fail("Failed to examine artifact: " + e.getMessage());

178

}

179

}

180

}

181

```

182

183

### Continuous Testing Utilities

184

185

```java

186

import io.quarkus.test.ContinuousTestingTestUtils;

187

import io.quarkus.test.QuarkusDevModeTest;

188

import org.junit.jupiter.api.Test;

189

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

190

191

public class ContinuousTestingTest {

192

193

@RegisterExtension

194

static final QuarkusDevModeTest config = new QuarkusDevModeTest()

195

.withApplicationRoot(jar -> jar.addClasses(MyService.class, MyTest.class));

196

197

@Test

198

public void testContinuousTesting() {

199

ContinuousTestingTestUtils testUtils = new ContinuousTestingTestUtils();

200

201

// Wait for initial test run to complete

202

ContinuousTestingTestUtils.TestStatus status = testUtils.waitForNextCompletion();

203

204

// Verify initial test results

205

assertTrue(status.getTestsRun() > 0);

206

assertEquals(0, status.getTestsFailed());

207

208

// Modify source file to trigger re-run

209

config.modifySourceFile("org/example/MyService.java", source ->

210

source.replace("return \"Hello\";", "return \"Hello World\";"));

211

212

// Wait for tests to run again

213

ContinuousTestingTestUtils.TestStatus newStatus = testUtils.waitForNextCompletion();

214

215

// Verify tests ran again

216

assertTrue(newStatus.getLastRun() > status.getLastRun());

217

assertTrue(newStatus.getTotalTestsPassed() >= status.getTotalTestsPassed());

218

}

219

220

@Test

221

public void testStatusTracking() {

222

ContinuousTestingTestUtils testUtils = new ContinuousTestingTestUtils();

223

ContinuousTestingTestUtils.TestStatus status = testUtils.waitForNextCompletion();

224

225

// Examine test status details

226

System.out.println("Tests run: " + status.getTestsRun());

227

System.out.println("Tests passed: " + status.getTestsPassed());

228

System.out.println("Tests failed: " + status.getTestsFailed());

229

System.out.println("Tests skipped: " + status.getTestsSkipped());

230

231

// Check cumulative totals

232

System.out.println("Total passed: " + status.getTotalTestsPassed());

233

System.out.println("Total failed: " + status.getTotalTestsFailed());

234

System.out.println("Total skipped: " + status.getTotalTestsSkipped());

235

236

// Verify status string representation

237

String statusString = status.toString();

238

assertTrue(statusString.contains("testsRun=" + status.getTestsRun()));

239

}

240

}

241

```

242

243

### Application Properties Utility

244

245

```java

246

@Test

247

public void testAppPropertiesGeneration() {

248

// Generate application properties

249

String properties = ContinuousTestingTestUtils.appProperties(

250

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

251

"app.name", "Test Application",

252

"app.version", "1.0.0"

253

);

254

255

// Verify generated properties format

256

assertTrue(properties.contains("quarkus.log.level=DEBUG"));

257

assertTrue(properties.contains("app.name=Test Application"));

258

assertTrue(properties.contains("app.version=1.0.0"));

259

260

// Use in test configuration

261

config.addResourceFile("application.properties", properties);

262

}

263

264

@Test

265

public void testComplexProperties() {

266

String properties = ContinuousTestingTestUtils.appProperties(

267

"quarkus.datasource.db-kind", "postgresql",

268

"quarkus.datasource.username", "test",

269

"quarkus.datasource.password", "test",

270

"quarkus.datasource.jdbc.url", "jdbc:postgresql://localhost:5432/testdb",

271

"quarkus.hibernate-orm.database.generation", "drop-and-create"

272

);

273

274

// Use for database testing

275

config.addResourceFile("application-test.properties", properties);

276

}

277

```

278

279

### Exclusivity Checking

280

281

```java

282

import io.quarkus.test.ExclusivityChecker;

283

import io.quarkus.test.QuarkusUnitTest;

284

import org.junit.jupiter.api.Test;

285

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

286

287

public class ExclusivityTest {

288

289

@Test

290

public void testExclusivityChecking() {

291

// This is typically used internally by test extensions

292

// but can be used directly if needed

293

294

ExtensionContext context = // ... get from JUnit

295

296

// Check that current test type doesn't conflict with others

297

ExclusivityChecker.checkTestType(context, QuarkusUnitTest.class);

298

299

// This will throw an exception if another test type is already running

300

}

301

}

302

```

303

304

### Cache Management

305

306

```java

307

import io.quarkus.test.ClearCache;

308

import org.junit.jupiter.api.BeforeEach;

309

import org.junit.jupiter.api.Test;

310

311

public class CacheManagementTest {

312

313

@BeforeEach

314

public void clearCaches() {

315

// Clear all internal caches before each test

316

// This ensures clean state between tests

317

ClearCache.clearCaches();

318

}

319

320

@Test

321

public void testWithCleanCache() {

322

// Test runs with cleared caches

323

// Useful for testing cache population, invalidation, etc.

324

}

325

326

@Test

327

public void testCacheClearing() {

328

// Populate some caches

329

// ... perform operations that cache data

330

331

// Clear caches

332

ClearCache.clearCaches();

333

334

// Verify caches are cleared

335

// ... check that cached data is no longer available

336

}

337

}

338

```

339

340

### Advanced Test Status Handling

341

342

```java

343

@Test

344

public void testAdvancedStatusHandling() {

345

ContinuousTestingTestUtils testUtils = new ContinuousTestingTestUtils();

346

347

// Create custom test status

348

ContinuousTestingTestUtils.TestStatus customStatus =

349

new ContinuousTestingTestUtils.TestStatus(

350

System.currentTimeMillis(), // lastRun

351

0, // running

352

10, // testsRun

353

9, // testsPassed

354

1, // testsFailed

355

0, // testsSkipped

356

45, // totalTestsPassed

357

2, // totalTestsFailed

358

1 // totalTestsSkipped

359

);

360

361

// Analyze status

362

double passRate = (double) customStatus.getTestsPassed() / customStatus.getTestsRun();

363

assertTrue(passRate > 0.8); // 80% pass rate

364

365

// Check if tests are currently running

366

assertFalse(customStatus.getRunning() > 0);

367

368

// Verify cumulative statistics

369

long totalTests = customStatus.getTotalTestsPassed() +

370

customStatus.getTotalTestsFailed() +

371

customStatus.getTotalTestsSkipped();

372

assertEquals(48, totalTests);

373

}

374

```

375

376

### Integration with Test Annotations

377

378

```java

379

public class IntegrationTest {

380

381

@ProdBuildResults

382

ProdModeTestResults results;

383

384

@LogFile

385

Path logFile;

386

387

@Test

388

public void testIntegration() {

389

// Use injected build results

390

assertNotNull(results);

391

assertTrue(Files.exists(results.getBuildDir()));

392

393

// Use injected log file

394

assertNotNull(logFile);

395

assertTrue(Files.exists(logFile));

396

397

// Verify they contain expected content

398

List<LogRecord> buildLogs = results.getRetainedBuildLogRecords();

399

assertFalse(buildLogs.isEmpty());

400

401

// Read log file content

402

try {

403

String logContent = Files.readString(logFile);

404

assertTrue(logContent.contains("Application started"));

405

} catch (IOException e) {

406

fail("Failed to read log file: " + e.getMessage());

407

}

408

}

409

}

410

```