description |
---|
Understand whats going on |
To gain insight into the inner workings of the Konsist test, examine the data provided by the Konsist API.
Two primary tools can help you comprehend the inner workings of the Konsist API are #evaluate-expression and #print-to-console.
The IntelliJ IDEA / Android Studio provides a handy feature called Evaluate Expressions which is an excellent tool for debugging Konsist tests.
Create a simple test class and click on the line number to add the breakpoint:
Debug the test:
When the program stops at the breakpoint (blue line background) run Evaluate Expression...
action...
...or press Evaluate Expression...
button:
In the Evaluate
window enter the code and click the Evaluate
the button. For example, you can list all of the classes present in the scope to get the class names:
You can also display a single-class declaration to view its name
:
koScope
.classes()
.first()
.name
Konsist provides a flexible API that allows to output of the specified data as console logs. Scopes, lists of declarations, and single declarations can all be printed.
Print a list of files from KoScope
:
koScope // KoScope
.print()
Print multiple declarations:
koScope
.classes() // List<KoClassDeclaration>
.print()
Print a given attribute for each declaration:
koScope
.classes() // List<KoClassDeclaration>
.print { it.fullyQualifiedName }
Print single declaration:
koScope
.classes() // List<KoClassDeclaration>
.first() // KoClassDeclaration
.print()
Print list of queried declarations before and after query:
koScope
.classes() // List<KoClassDeclaration>
.print(prefix = "Before") // or .print(prefix = "Before") { it.name }
.withSomeAnnotations("Logger")
.print(prefix = "After") // or .print(prefix = "After") { it.name }
Print nested declarations:
koScope
.classes() // List<KoClassDeclaration>
.constructors // List<KoConstructorDeclaration>
.parameters // List<KoParameterDeclaration>
.print()