CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-io-quarkus--quarkus-junit5-internal

A runner for unit tests, intended for testing Quarkus rather than for end user consumption.

Pending
Overview
Eval results
Files

results-utilities.mddocs/

Result Containers and Utilities

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

ProdModeTestResults

Container for production mode test build results.

Core API

public class ProdModeTestResults {
    
    public ProdModeTestResults(Path buildDir, Path builtArtifactPath, 
        List<ArtifactResult> results, List<LogRecord> retainedBuildLogRecords);
    
    public Path getBuildDir();
    public Path getBuiltArtifactPath();
    public List<ArtifactResult> getResults();
    public List<LogRecord> getRetainedBuildLogRecords();
}

ContinuousTestingTestUtils

Utilities for testing continuous testing functionality.

Core API

public class ContinuousTestingTestUtils {
    
    public TestStatus waitForNextCompletion();
    public static String appProperties(String... props);
}

Nested Types

public static class TestStatus {
    public TestStatus();
    public TestStatus(long lastRun, long running, long testsRun, long testsPassed, 
        long testsFailed, long testsSkipped, long totalTestsPassed, 
        long totalTestsFailed, long totalTestsSkipped);
    
    // Status properties
    public long getLastRun();
    public void setLastRun(long lastRun);
    public long getRunning();
    public void setRunning(long running);
    public long getTestsRun();
    public void setTestsRun(long testsRun);
    public long getTestsPassed();
    public void setTestsPassed(long testsPassed);
    public long getTestsFailed();
    public void setTestsFailed(long testsFailed);
    public long getTestsSkipped();
    public void setTestsSkipped(long testsSkipped);
    public long getTotalTestsPassed();
    public void setTotalTestsPassed(long totalTestsPassed);
    public long getTotalTestsFailed();
    public void setTotalTestsFailed(long totalTestsFailed);
    public long getTotalTestsSkipped();
    public void setTotalTestsSkipped(long totalTestsSkipped);
    
    public String toString();
}

ExclusivityChecker

Ensures different test types don't run concurrently.

Core API

public class ExclusivityChecker {
    
    public static void checkTestType(ExtensionContext extensionContext, Class<?> current);
}

Constants

ExclusivityChecker

Ensures different test types don't run concurrently.

Core API

public class ExclusivityChecker {
    
    public static void checkTestType(ExtensionContext extensionContext, Class<?> current);
}

Constants

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

ClearCache

Utility for clearing various internal caches.

Core API

public class ClearCache {
    
    public static void clearCaches();
}

Usage Examples

Working with Production Build Results

import io.quarkus.test.ProdBuildResults;
import io.quarkus.test.ProdModeTestResults;
import io.quarkus.test.QuarkusProdModeTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

public class BuildResultsTest {
    
    @RegisterExtension
    static final QuarkusProdModeTest config = new QuarkusProdModeTest()
        .withApplicationRoot(jar -> jar.addClasses(MyService.class))
        .setRun(false); // Build only
    
    @ProdBuildResults
    ProdModeTestResults buildResults;
    
    @Test
    public void testBuildResults() {
        // Access build directory
        Path buildDir = buildResults.getBuildDir();
        assertTrue(Files.exists(buildDir));
        
        // Access built artifact
        Path artifact = buildResults.getBuiltArtifactPath();
        assertTrue(Files.exists(artifact));
        assertTrue(artifact.toString().endsWith(".jar"));
        
        // Examine build artifacts
        List<ArtifactResult> results = buildResults.getResults();
        assertFalse(results.isEmpty());
        
        // Check build logs
        List<LogRecord> buildLogs = buildResults.getRetainedBuildLogRecords();
        assertTrue(buildLogs.stream()
            .anyMatch(log -> log.getMessage().contains("BUILD SUCCESS")));
    }
    
    @Test
    public void testArtifactContents() {
        Path artifact = buildResults.getBuiltArtifactPath();
        
        // Examine JAR contents
        try (JarFile jarFile = new JarFile(artifact.toFile())) {
            // Verify main class
            Manifest manifest = jarFile.getManifest();
            String mainClass = manifest.getMainAttributes().getValue("Main-Class");
            assertNotNull(mainClass);
            
            // Verify application classes are present
            assertNotNull(jarFile.getEntry("org/example/MyService.class"));
            
            // Verify dependencies are included
            assertNotNull(jarFile.getEntry("META-INF/quarkus/"));
            
        } catch (IOException e) {
            fail("Failed to examine artifact: " + e.getMessage());
        }
    }
}

Continuous Testing Utilities

import io.quarkus.test.ContinuousTestingTestUtils;
import io.quarkus.test.QuarkusDevModeTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

public class ContinuousTestingTest {
    
    @RegisterExtension
    static final QuarkusDevModeTest config = new QuarkusDevModeTest()
        .withApplicationRoot(jar -> jar.addClasses(MyService.class, MyTest.class));
    
    @Test
    public void testContinuousTesting() {
        ContinuousTestingTestUtils testUtils = new ContinuousTestingTestUtils();
        
        // Wait for initial test run to complete
        ContinuousTestingTestUtils.TestStatus status = testUtils.waitForNextCompletion();
        
        // Verify initial test results
        assertTrue(status.getTestsRun() > 0);
        assertEquals(0, status.getTestsFailed());
        
        // Modify source file to trigger re-run
        config.modifySourceFile("org/example/MyService.java", source ->
            source.replace("return \"Hello\";", "return \"Hello World\";"));
        
        // Wait for tests to run again
        ContinuousTestingTestUtils.TestStatus newStatus = testUtils.waitForNextCompletion();
        
        // Verify tests ran again
        assertTrue(newStatus.getLastRun() > status.getLastRun());
        assertTrue(newStatus.getTotalTestsPassed() >= status.getTotalTestsPassed());
    }
    
    @Test
    public void testStatusTracking() {
        ContinuousTestingTestUtils testUtils = new ContinuousTestingTestUtils();
        ContinuousTestingTestUtils.TestStatus status = testUtils.waitForNextCompletion();
        
        // Examine test status details
        System.out.println("Tests run: " + status.getTestsRun());
        System.out.println("Tests passed: " + status.getTestsPassed());
        System.out.println("Tests failed: " + status.getTestsFailed());
        System.out.println("Tests skipped: " + status.getTestsSkipped());
        
        // Check cumulative totals
        System.out.println("Total passed: " + status.getTotalTestsPassed());
        System.out.println("Total failed: " + status.getTotalTestsFailed());
        System.out.println("Total skipped: " + status.getTotalTestsSkipped());
        
        // Verify status string representation
        String statusString = status.toString();
        assertTrue(statusString.contains("testsRun=" + status.getTestsRun()));
    }
}

Application Properties Utility

@Test
public void testAppPropertiesGeneration() {
    // Generate application properties
    String properties = ContinuousTestingTestUtils.appProperties(
        "quarkus.log.level", "DEBUG",
        "app.name", "Test Application",
        "app.version", "1.0.0"
    );
    
    // Verify generated properties format
    assertTrue(properties.contains("quarkus.log.level=DEBUG"));
    assertTrue(properties.contains("app.name=Test Application"));
    assertTrue(properties.contains("app.version=1.0.0"));
    
    // Use in test configuration
    config.addResourceFile("application.properties", properties);
}

@Test
public void testComplexProperties() {
    String properties = ContinuousTestingTestUtils.appProperties(
        "quarkus.datasource.db-kind", "postgresql",
        "quarkus.datasource.username", "test",
        "quarkus.datasource.password", "test",
        "quarkus.datasource.jdbc.url", "jdbc:postgresql://localhost:5432/testdb",
        "quarkus.hibernate-orm.database.generation", "drop-and-create"
    );
    
    // Use for database testing
    config.addResourceFile("application-test.properties", properties);
}

Exclusivity Checking

import io.quarkus.test.ExclusivityChecker;
import io.quarkus.test.QuarkusUnitTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtensionContext;

public class ExclusivityTest {
    
    @Test
    public void testExclusivityChecking() {
        // This is typically used internally by test extensions
        // but can be used directly if needed
        
        ExtensionContext context = // ... get from JUnit
        
        // Check that current test type doesn't conflict with others
        ExclusivityChecker.checkTestType(context, QuarkusUnitTest.class);
        
        // This will throw an exception if another test type is already running
    }
}

Cache Management

import io.quarkus.test.ClearCache;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class CacheManagementTest {
    
    @BeforeEach
    public void clearCaches() {
        // Clear all internal caches before each test
        // This ensures clean state between tests
        ClearCache.clearCaches();
    }
    
    @Test
    public void testWithCleanCache() {
        // Test runs with cleared caches
        // Useful for testing cache population, invalidation, etc.
    }
    
    @Test 
    public void testCacheClearing() {
        // Populate some caches
        // ... perform operations that cache data
        
        // Clear caches
        ClearCache.clearCaches();
        
        // Verify caches are cleared
        // ... check that cached data is no longer available
    }
}

Advanced Test Status Handling

@Test
public void testAdvancedStatusHandling() {
    ContinuousTestingTestUtils testUtils = new ContinuousTestingTestUtils();
    
    // Create custom test status
    ContinuousTestingTestUtils.TestStatus customStatus = 
        new ContinuousTestingTestUtils.TestStatus(
            System.currentTimeMillis(), // lastRun
            0,  // running
            10, // testsRun
            9,  // testsPassed
            1,  // testsFailed
            0,  // testsSkipped
            45, // totalTestsPassed
            2,  // totalTestsFailed
            1   // totalTestsSkipped
        );
    
    // Analyze status
    double passRate = (double) customStatus.getTestsPassed() / customStatus.getTestsRun();
    assertTrue(passRate > 0.8); // 80% pass rate
    
    // Check if tests are currently running
    assertFalse(customStatus.getRunning() > 0);
    
    // Verify cumulative statistics
    long totalTests = customStatus.getTotalTestsPassed() + 
                     customStatus.getTotalTestsFailed() + 
                     customStatus.getTotalTestsSkipped();
    assertEquals(48, totalTests);
}

Integration with Test Annotations

public class IntegrationTest {
    
    @ProdBuildResults
    ProdModeTestResults results;
    
    @LogFile
    Path logFile;
    
    @Test
    public void testIntegration() {
        // Use injected build results
        assertNotNull(results);
        assertTrue(Files.exists(results.getBuildDir()));
        
        // Use injected log file
        assertNotNull(logFile);
        assertTrue(Files.exists(logFile));
        
        // Verify they contain expected content
        List<LogRecord> buildLogs = results.getRetainedBuildLogRecords();
        assertFalse(buildLogs.isEmpty());
        
        // Read log file content
        try {
            String logContent = Files.readString(logFile);
            assertTrue(logContent.contains("Application started"));
        } catch (IOException e) {
            fail("Failed to read log file: " + e.getMessage());
        }
    }
}

Install with Tessl CLI

npx tessl i tessl/maven-io-quarkus--quarkus-junit5-internal

docs

build-chain-customization.md

dev-mode-testing.md

index.md

logging-test-resources.md

prod-mode-testing.md

results-utilities.md

unit-testing.md

tile.json