> For the complete documentation index, see [llms.txt](https://docs.konsist.lemonappdev.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.konsist.lemonappdev.com/features/debug-konsist-test.md).

# Debug Konsist Test

Understand what's going on

To gain insight into the inner workings of the Konsist test, examine the data provided by the Konsist API.

Two primary tools that can help you comprehend the inner workings of the Konsist API are [#evaluate-expression-debugger-window](#evaluate-expression-debugger-window "mention") and [#print-to-console](#print-to-console "mention").

## Evaluate Expression Debugger Window

The [IntelliJ IDEA](https://www.jetbrains.com/idea/) / [Android Studio](https://developer.android.com/studio) provides a handy feature called [Evaluate Expressions](https://www.jetbrains.com/help/idea/evaluating-expressions.html) which is an excellent tool for debugging Konsist tests.

Create a simple test class and click on the line number to add the [breakpoint](https://www.jetbrains.com/help/idea/using-breakpoints.html):

<figure><img src="https://3782930697-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRYeSMx6WDKivnwWx7PdP%2Fuploads%2FajMEdUWyaGx2AOEIR3Lz%2Fimage.png?alt=media&amp;token=3e05b66c-5e9e-43d7-bc7a-aaab0e8a0e87" alt=""><figcaption></figcaption></figure>

Debug the test:

<figure><img src="https://3782930697-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRYeSMx6WDKivnwWx7PdP%2Fuploads%2FwSerGcoZJaGRV58Hwbil%2Fimage.png?alt=media&amp;token=927d7d26-93de-4898-8f6c-d3ed4f17a41f" alt=""><figcaption></figcaption></figure>

When the program stops at the breakpoint (blue line background) run `Evaluate Expression...` action...

<figure><img src="https://3782930697-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRYeSMx6WDKivnwWx7PdP%2Fuploads%2FKUmVT1311SmemwgnDrTo%2Fimage.png?alt=media&amp;token=9bbc8022-da00-4793-a032-c277b6cfdb91" alt=""><figcaption></figcaption></figure>

...or press `Evaluate Expression...` button:

<figure><img src="https://3782930697-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRYeSMx6WDKivnwWx7PdP%2Fuploads%2FsVi8xkfsquvL3n98taMF%2Fimage.png?alt=media&amp;token=963fae2a-8a91-476f-9438-4fcfc85fff5b" alt=""><figcaption></figcaption></figure>

In the `Evaluate` window enter the code and click the `Evaluate` button. For example, you can list all of the classes present in the scope to get the class names:

<figure><img src="https://3782930697-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRYeSMx6WDKivnwWx7PdP%2Fuploads%2Fzw6fIW0ODTil8YEWQZbL%2Fimage.png?alt=media&amp;token=7722d32f-9fea-416f-9db7-53c420c20b39" alt=""><figcaption></figcaption></figure>

You can also display a single-class declaration to view its `name`:

```kotlin
koScope
    .classes()
    .first()
    .name
```

## Print To Console

Konsist provides a flexible API that allows outputting the specified data as console logs. Scopes, lists of declarations, and single declarations can all be printed.

Print a list of files from `KoScope`:

```kotlin
koScope // KoScope
    .print()
```

Print multiple declarations:

```kotlin
koScope
    .classes() // List<KoClassDeclaration>
    .print()
```

Print a given attribute for each declaration:

```kotlin
koScope
    .classes() // List<KoClassDeclaration>
    .print { it.fullyQualifiedName.orEmpty() }
```

Print single declaration:

```kotlin
koScope
    .classes() // List<KoClassDeclaration>
    .first() // KoClassDeclaration
    .print()
```

Print list of queried declarations before and after query:

```kotlin
koScope
    .classes() // List<KoClassDeclaration>
    .print(prefix = "Before") // or .print(prefix = "Before") { it.name }
    .withAnnotationNamed("Logger")
    .print(prefix = "After") // or .print(prefix = "After") { it.name }
```

Print nested declarations:

```kotlin
koScope
    .classes() // List<KoClassDeclaration>
    .constructors // List<KoConstructorDeclaration>
    .parameters //  List<KoParameterDeclaration>
    .print()
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.konsist.lemonappdev.com/features/debug-konsist-test.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
