# Making code folding work within Unit Tests

**URL:** <https://platform.jetbrains.com/t/making-code-folding-work-within-unit-tests/2231>\
**Category:** IntelliJ Platform\
**Created:** [July 10, 2025, 1:26pm UTC](https://platform.jetbrains.com/t/making-code-folding-work-within-unit-tests/2231 "2025-07-10T13:26:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaroslav.kavalec](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/jaroslav.kavalec/32/1426_2.png) [@jaroslav.kavalec](https://platform.jetbrains.com/u/jaroslav.kavalec)\
**Post date:** [July 10, 2025, 1:26pm UTC](https://platform.jetbrains.com/t/making-code-folding-work-within-unit-tests/2231/1 "2025-07-10T13:26:32Z")

</div>

For my plugin I need editor tests where some code is folded - lets say I want to have folded class within example.

Before being even able work with folding properties, I hit issue that my code that is foldable when pasted into Kotlin editor, but has no folding regions ({editor.foldingModel.allFoldRegions.size is 0) inside editor.foldingModel.

I tried to make it work with some crappy AI suggestions i.e. doHighlights, playing with codeFoldingManager, but to no avail.

Here is the code:

```auto
class FoldingTest : BasePlatformTestCase() {
	fun testFolding() {
        val code = """
        import com.test.First
        import com.test.Second
        import com.test.Third
        
        class MyClass {
            fun foo() {
                println("Hello")
            }
        }""".trimIndent()
		println(code)
		myFixture.configureByText("test.kt", code)
		
		val editor = myFixture.editor
		val settings = myFixture.editor.settings
		
		editor.settings.isAutoCodeFoldingEnabled = true
		editor.settings.isFoldingOutlineShown = true
		
		myFixture.doHighlighting()
		
		val codeFoldingManager = CodeFoldingManager.getInstance(myFixture.project)
		codeFoldingManager.updateFoldRegions(myFixture.editor)
		
		//here I expect 2 not 0
		println("Number of fold regions: ${editor.foldingModel.allFoldRegions.size}")
	}
}

```

I need to get class folded so that I can start running tests against my folding dependent plugin code.

---

<div class="post-metadata">

**Author:** ![picimako](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/picimako/32/171_2.png) [@picimako](https://platform.jetbrains.com/u/picimako)\
**Post date:** [July 13, 2025, 1:50pm UTC](https://platform.jetbrains.com/t/making-code-folding-work-within-unit-tests/2231/2 "2025-07-13T13:50:41Z")

</div>

Hi @jaroslav.kavalec,

In case you haven’t done so, please check the `testFolding*()` methods inside `CodeInsightTestFixture`.

---

<div class="post-metadata">

**Author:** ![jaroslav.kavalec](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/jaroslav.kavalec/32/1426_2.png) [@jaroslav.kavalec](https://platform.jetbrains.com/u/jaroslav.kavalec)\
**Post date:** [July 19, 2025, 12:54pm UTC](https://platform.jetbrains.com/t/making-code-folding-work-within-unit-tests/2231/3 "2025-07-19T12:54:24Z")

</div>

Thank you, this lead me in the right direction.
