QuickPerf Documentation
repository·master·Indexed 19 days ago
https://github.com/quick-perf/quickperfA Java testing library for evaluating and improving performance properties using annotations. It enables monitoring and asserting JVM heap allocation and SQL query counts within JUnit 4, JUnit 5, and TestNG test suites, with specific support for detecting N+1 select issues in Hibernate and Spring Data JPA.
What's inside QuickPerf
- QuickPerf is a Java testing library designed to quickly evaluate and improve performance-related properties of your application. It allows developers to use annotations to monitor and assert performance metrics such as JVM heap allocation and SQL query counts directly within their test suites.
Use SpringRunnerWithQuickPerfFeatures for Spring 5 JUnit 4 tests
masterWhen writing JUnit 4 tests for Spring 5 applications, use
SpringRunnerWithQuickPerfFeaturesas your test runner to enable QuickPerf performance monitoring features alongside the Spring TestContext Framework. This runner combines the capabilities ofSpringJUnit4ClassRunnerwithQuickPerfJUnitRunner.@RunWith(SpringRunnerWithQuickPerfFeatures.class) @ContextConfiguration(classes = MyConfig.class) public class MySpringTest { // Your performance-monitored Spring tests }Use SQL annotations to monitor database queries
masterQuickPerf provides annotations to assert the number of SQL statements executed during a test. This is particularly useful for detecting N+1 select issues in Hibernate or Spring Data JPA.
Example: Use
@ExpectSelect(n)to assert that exactlynselect statements are executed.QuickPerf automatically detects Hibernate and Spring Data JPA and provides actionable suggestions (e.g., using
JOIN FETCHor@EntityGraph) when assertions fail.@ExpectSelect(1) @Test public void should_find_all_players() { ... }Use JVM annotations to measure heap allocation
masterYou can monitor JVM performance metrics by applying annotations to your test methods. For example, to measure heap allocation and assert a specific heap size limit, use
@MeasureHeapAllocationand@HeapSize.Supported test frameworks include JUnit 4, JUnit 5, and TestNG.
@MeasureHeapAllocation @HeapSize(value = 1, unit = AllocationUnit.GIGA_BYTE) @Test public void execute_batch() { ... }View QuickPerf debug information in the console
masterWhen troubleshooting QuickPerf configuration or execution order, you can view debug information in the standard output. The
displayQuickPerfDebugInfosmethod outputs:- JVM Options: A list of the JVM options used during execution.
- Recorder Execution Order: The priority and class names of recorders executed before and after test methods, determined by the
QuickPerfConfigLoaderimplementations found viaServiceLoader.
This is useful for verifying if your custom recorders are being loaded in the expected priority order.
// Note: ConsoleReporter is package-private in the source, // but its methods are used by the framework to output debug info. consoleReporter.displayQuickPerfDebugInfos(jvmOptions);View applied QuickPerf annotations in the console
masterThe
displayQuickPerfAnnotationsmethod outputs the specific QuickPerf annotations applied to a test or class to the console.It provides:
- A comma-separated list of the applied annotations (formatted via
AnnotationFormatter). - The canonical name of the class that specifies global annotations (if any are configured via
SpecifiableGlobalAnnotations).
Note that the
DisplayAppliedAnnotationsannotation itself is filtered out of the output to avoid redundancy.// This method is called by the framework to report which // annotations are currently active in the test context. consoleReporter.displayQuickPerfAnnotations(perfAnnotations);- A comma-separated list of the applied annotations (formatted via