|
| 1 | +--- |
| 2 | +sidebar_position: 5.5 |
| 3 | +sidebar_label: Logging for Object Resolution |
| 4 | +--- |
| 5 | + |
| 6 | +import { JavaKotlinCodeBlock, JavadocLink } from '@site/src/components/Custom'; |
| 7 | +import { version } from '../data.json'; |
| 8 | + |
| 9 | +# Logging for Object Resolution |
| 10 | + |
| 11 | +AutoParams provides detailed logging capabilities that help you understand how objects are being resolved during test execution. The resolution log is printed to standard output during test execution, making it easy to trace how each value is generated. |
| 12 | + |
| 13 | +For example, resolving a `User` class now produces a detailed trace. Given the following class: |
| 14 | + |
| 15 | +<JavaKotlinCodeBlock> |
| 16 | +```java |
| 17 | +@AllArgsConstructor |
| 18 | +@Getter |
| 19 | +public class User { |
| 20 | + |
| 21 | + private final UUID id; |
| 22 | + private final String email; |
| 23 | + private final String username; |
| 24 | +} |
| 25 | +``` |
| 26 | +</JavaKotlinCodeBlock> |
| 27 | + |
| 28 | +Running the following code: |
| 29 | + |
| 30 | +<JavaKotlinCodeBlock> |
| 31 | +```java |
| 32 | +ResolutionContext context = new ResolutionContext(); |
| 33 | +User user = context.resolve(); |
| 34 | +``` |
| 35 | +</JavaKotlinCodeBlock> |
| 36 | + |
| 37 | +Will print a hierarchical visualization of the resolution process: |
| 38 | + |
| 39 | +```text |
| 40 | +▼ Resolving for: class your.app.User |
| 41 | +├── ▼ Resolving for: interface autoparams.generator.ConstructorResolver |
| 42 | +│ ├── ▼ Resolving for: interface autoparams.generator.ConstructorExtractor |
| 43 | +│ │ ✓ Resolved: autoparams.generator.DefaultConstructorExtractor@3b39e79b for: interface autoparams.generator.ConstructorExtractor |
| 44 | +│ ✓ Resolved: autoparams.generator.CompositeConstructorResolver@6dded900 for: interface autoparams.generator.ConstructorResolver |
| 45 | +│ |
| 46 | +├── ▼ Resolving for: Parameter final java.lang.Long id |
| 47 | +│ ✓ Resolved: 15775 for: Parameter final java.lang.Long id |
| 48 | +│ |
| 49 | +├── ▼ Resolving for: Parameter final java.lang.String email |
| 50 | +│ ├── ▼ Resolving for: class autoparams.generator.EmailAddressGenerationOptions |
| 51 | +│ │ ✓ Resolved: EmailAddressGenerationOptions[domains=["test.com"]] for: class autoparams.generator.EmailAddressGenerationOptions |
| 52 | +│ ✓ Resolved: [email protected] for: Parameter final java.lang.String email |
| 53 | +│ |
| 54 | +├── ▼ Resolving for: Parameter final java.lang.String username |
| 55 | +│ ✓ Resolved: username6942b0dc-da65-42ca-a756-4303fcb6328a for: Parameter final java.lang.String username |
| 56 | +✓ Resolved: your.app.User@56835f2f for: class your.app.User |
| 57 | +``` |
| 58 | + |
| 59 | +The log uses the following symbols to represent the resolution flow: |
| 60 | +- `▼` indicates the start of a resolution attempt |
| 61 | +- `├──` shows nested resolution steps |
| 62 | +- `✓` indicates successful resolution |
| 63 | +- Indentation levels represent the depth of the resolution chain |
| 64 | + |
| 65 | +This logging is particularly valuable when working with: |
| 66 | +- Customizations |
| 67 | +- Complex object hierarchies |
| 68 | +- Dependency injection scenarios |
| 69 | +- Debugging test failures related to object generation |
0 commit comments