TS 68 JavaEditorCodeFolding

Test Specification: Code Folding Feature

Author: Roman Strobl & Max Sauer & Petr Dvorak & Jiri Prox
Version: 6.8
Introduction: This document serves as a test specification for editor module, more specifically to the feature code folding. Code folding allows user of IDE to collapse and expand portions of code so that less important or generated code is hidden, leaving more space for remaining code that needs to be visible in particular time.
Setup: Start IDE with a fresh userdir (switch "-- userdir /path/to/some/dir")


Test suite: Basic Code Folding

  1. Code folding after opening a file
    1. Open File:CodeFolding.java CodeFolding.java file
      - All folds are identified and expanded by default, so that user can see the whole source code.
      - Fold marks must be presented by initial comments, import statemets, javadoc comments, inner class and methods
      - Folds must be painted similarly to this:

      File:Code folding java.png image

  1. Adding/Removing code
    1. Create a new Java class
    2. Add this code into class body:
public void myMethodX() { System.out.println(); } public void myMethodY() { }
    1. Add javadoc comment before the method myMethodY:
   /** My javadoc for myMethodY */
    1. Add import statement in adequate place in source file:

import java.lang.String;

    1. Add inner class inside class body:
   class MyInnerClass {
    1. Add method into inner class:
  class MyInnerClass {
      void myInnerClassMehod() {
    1. Remove source code you typed in previous steps (select it and press Delete, for example)
      - Code folds must be added immediately after a code is added
      - When code is removed, fold must be removed as well.
  1. Options - Collapse by Default
    1. Open Tools|Options|Editor|General and check names, mnemonics and default states of components options under Code Folding settings
    2. Change settings for code folding - pick randomly some options (perform this test case a few times with various settings..., the 'Tags and other code block' option is related to html files)
    3. Leave the option "Use Code Folding" enabled
    4. Confirm the dialog with OK button
    5. Open any java file
    • EXPECTED RESULT: Check the state of all types of code folds in opened file. Code folds are currently updated only for newly opened files (thus you need to close and reopen a file in order to see the effect of changed settings immediately).
  1. Options - Disable/Enable CF
    1. Open options for Code Folding dialog in Tools|Options|Editor|General
    2. Uncheck Use Code Folding checkbox
      - All fold marks must be removed from editor when you disable code folding and all previously collapsed portions of code must be expanded.
      - Fold marks must be shown in the way that reflects Code Folding settings under Tools
  1. Options - Typing in editor
    1. Enable CF if it's disabled from previous testcase
    2. Enabled default folding of all elements
    3. Open/create new java file
    4. Write some code in editor
    • EXPECTED RESULT: All folds are collapsed when file is opened. When editing the folds keep it status. The only exception is when enter is pressed behind the closing symbol ( } or */ ). In this situation the folder is collapsed
  1. Options - Scrolling
    1. Enabled default folding of all elements
    2. new java file A with 3 method a ,b, c (they are written in file in this order)
    3. method a,b are longer then editor view (may be empty)
    4. close A
    5. create class B calling method A.b()
    6. ctrl-click on the reference to b()
    • {{{1}}}

Test suite: Defining Custom Code Folding

Setup: Create a new Java class

  1. Add custom code fold
    1. Add custom opening mark //<editor-fold> to the beginning of a file
    2. Add ending mark //</editor-fold> to the bottom of the same file
    3. Close and re-open the file
    • EXPECTED RESULT: The user defined fold must be correctly recognized when added. When file is re-opened, user defined code fold is in expanded state (source code is visible).
  1. Add custom code fold with description
    1. Add property "desc" to the opening mark of the custom fold from the previous test case, for example: //<editor-fold desc="This is my code fold">
    2. Click the little [[[- | [-]] sign in order to collapse the single code fold (→ code fold is collapsed)
    3. Expand the code fold by clicking the little [[[+ | [+]] sign (→ code fold is expanded again)
    • EXPECTED RESULT: When the custom code fold with description is collapsed, you can see the border with a description (instead of just "...") in the editor.
  1. Add custom code fold (collapse by default)
    1. Add property "defaultstate" to the opening mark of the custom fold from the previous test case: //<editor-fold defaultstate="collapsed">
    2. Close and re-open the file
    • EXPECTED RESULT: The user defined fold must be in collapsed state after you reopen the file (source code is NOT visible).
  1. Change custom code fold
    1. Expand the custom code fold you created in previous test cases
    2. Remove the ending mark and place it just behind the first comment in the file (so that opening and closing marks enclose the first comment)
    • EXPECTED RESULT: The folds must be updated and correctly repainted
  1. Remove custom code fold
    1. Remove user fold (remove both marks)
    • EXPECTED RESULT: Code fold is correctly removed and there are no painting issues.

Test suite: Code Folding Actions

  1. CF Mouse Actions
    1. Code folds are indicated by the [[[+ | [+]] or [[[- | [-]] mark, depending on the state of the fold, as depicted here (colors are just for demonstration):
    2. To collapse a code fold, click the [[[- | [-]] mark of that fold
    3. To expand a code fold, click the [[[+ | [+]] mark of that fold
    4. Doble click on any collapsed code (indicated with border with "..." or description) in order to to expand the code fold
    • EXPECTED RESULT: Folds are collapsed/expanded as expected.
  1. Code Folding main menu
    1. Check content of "Code Folding" menu under View|Code Folds
    • EXPECTED RESULT: Following items must be present in the menu:
      - Collapse Fold
      - Expand Fold
      - Collapse All
      - Expand All
      - Collapse All JavaDoc
      - Expand All JavaDoc
      - Collapse All JavaCode
      - Expand All JavaCode
  1. Collapse and expand single code fold
    1. Move caret inside method's body, collapse method's body using View|Code Folds|Collapse Fold
    2. Expand the method using View|Code Folds|Expand Fold
    3. Place caret on opening or closing mark of custom code fold, collapse custom code fold from the main menu
    4. Expand custom fold using main menu
    5. Move cursor in front of the method's declaration (the beginning of method's declaration row), collapse method from the main menu
    6. Expand the method using main menu
    7. Move cursor behind the end of a method's body (after closing brace "}") and collapse method from the main menu
    8. Expand the method using main menu
    9. Place caret on a row with JavaDoc comment, collapse JavaDoc comment from the main menu
    10. Expand the JavaDoc using main menu
    11. Place caret inside a method of some inner class, collapse method from the main menu
    12. Expand the method that you just collapsed using main menu
    13. Place caret inside some inner class, collapse inner class from the main menu
    14. Expand the inner class using main menu
    • EXPECTED RESULT: Collapsing and expanding code folds works as expected when you invoke main menu actions. Whenever code fold is collapsed, caret is placed in front of ... mark in the editor
  1. Collapse and expand all code folds
    1. Invoke "Collapse All" action from the main menu (View|Code Folds|Collapse All)
    2. Invoke "Expand All" action from the main menu (View|Code Folds|Expand All)
    3. Invoke "Collapse All JavaDoc" action from the main menu (View|Code Folds|Collapse All Javadoc)
    4. Invoke "Expand All JavaDoc" action from the main menu (View|Code Folds|Expand All Javadoc)
    5. Invoke "Collapse All Java Code" action from the main menu (View|Code Folds|Collapse All Java Code)
    6. Invoke "Expand All Java Code" action from the main menu (View|Code Folds|Expand All Java Code)
    7. Try to invoke above mentioned actions from editor's popup menu (Code Folds|...)
    • EXPECTED RESULT: All folds (or all folds of a particular type) in currently opened file must be collapsed and expanded as expected after performing an action.
  1. CF Shortcut Actions
    1. Use shortcut to collapse single code fold (Ctrl+'-')
    2. Use shortcut to expand single code fold (Ctrl+'+')
    3. Use shortcuts for "Collapse All" (Ctrl+Shift+'-') and "Expand All" (Ctrl+Shift+'+') actions
    • EXPECTED RESULT: Keyboard shortcuts work as expected, performing the same actions as corresponding actions invoked from the main menu
  1. Show Collapsed Code in Tooltip
    1. Move the mouse cursor above the collapsed code (border with "..." or description)
    • EXPECTED RESULT: Collapsed code is showed in tooltip, it is colored and indented.
  1. Open No Parsable File
    1. Open a corrupted file File:CodeFoldingWrong.java CodeFoldingWrong.java
    • EXPECTED RESULT: Code folds should be painted properly where possible.
  1. Empty File
    1. Create file "Java Main Class"
    2. Select all code using Ctrl+A
    3. Press Delete
    • EXPECTED RESULT: All content should be erased, including the CF

Test suite: Overlapped or corrupted folds, edge cases

  1. Overlapped folds
    1. Create custom fold that overlap a method fold :


   public void CodeFolding() {


    1. Try to remove the custom fold
    • EXPECTED RESULT: The fold for method should be visible. Custom fold is not recognized
  1. Corrupt Custom Folds 1
    1. Insert closing mark (//</editor-fold>) in editor
    2. Insert the opening mark behind the closing one (on the same row)
    3. Cut the opening mark and move it before the closing one (on the same row)
    4. Place caret between the opening and closing mark and hit enter
    • EXPECTED RESULT: No exceptions are thrown, code folds are recognized when opening mark is placed before the closing mark.
  1. Corrupt Custom Folds 2
    1. Insert character 'a' in closing mark in order to corrupt it, for example: //</aeditor-fold>
    2. Remove the 'a' from the mark in order to fix it
    • EXPECTED RESULT: Code fold is removed when you corrupt closing mark and recreated when you fix it.
  1. Corrupt Custom Folds 3
    1. Add 4 closing marks to the Java file:

//</editor-fold> //</editor-fold> //</editor-fold> //</editor-fold>

    1. Add the opening marks before them using copy&paste:

//<editor-fold desc="aaa"> //<editor-fold desc="bbb"> //<editor-fold desc="ccc"> //<editor-fold desc="ddd">

    1. Add user fold with the same name at end of file :

//<editor-fold desc="aaa"> //</editor-fold>

    • EXPECTED RESULT: All folds must be recognized and collapsable. It is possible have more user defined folds with the same description (desc).
  1. Comments after block
    1. Add a comment behind a method's body (on the same row), like this "... } // my comment and collapse the method using the [[[- | [-]] sign
    • EXPECTED RESULT: The comment is visible when the code fold is collapsed.
  1. Two methods on the same line
    1. Add two methods on the same row, e.g. void aaa() { } void bbb() { }
    2. Try to collapse the code fold on the row
    • EXPECTED RESULT: Only the second method should be collapsed. A method can't be collapsed when there is another method on the same row.
  1. JavaDoc / Normal comment
    1. Remove the leading star from the beginning of a JavaDoc comment, so that Javadoc comment /** ... */ becomes normal comment /* ... */
    2. Add the star back to the comment so that it becomes a JavaDoc again
    3. Try to remove the beginning and end of a JavaDoc comment (/** and */)
    • EXPECTED RESULT: Code fold should be present only for JavaDoc comment, it has to disappear when JavaDoc comment becomes a normal comment and the other way around

Test suite: Miscellaneous

  1. Deleting when CF is collapsed
    1. Have a collapsed code fold
    2. Move the caret in front of the collapsed fold and hit Delete key
    3. Undo the last change and collapse the code fold again
    4. Move the caret behind the collapsed fold and hit Backspace key
    • EXPECTED RESULT: Code fold must be expanded when you press Delete/Backspace and the first/last character of the code inside the code fold must be removed
  2. Interaction with Surrounding Features 1 - Basic
    1. Check that showing/hiding line numbers (View|Show Line Numbers) this has no affect to CF
    2. Move caret before collapsed code fold (before the code fold mark, which is the border with "..." or with description)
    3. Move the caret over the CF mark and back using and keys
    4. Select collapsed code fold mark by keyboard (place caret just before CF mark, hold Shift and press )
    5. Press Delete to erase the content of the code fold and to remove the code fold
    6. Undo (Ctrl+Z) the last operation to restore the content and code folds
    • EXPECTED RESULT: The caret must be moved over the mark the same way as over a character. You can delete and restore whole code fold.
  3. Interactions with Surrounding Features 2 - Bookmarks
    1. Place a bookmark in a method
    2. Collapse the method
    3. Reach the bookmark by "Next Bookmark" action
    • EXPECTED RESULT: Fold must be expanded and caret placed on the bookmark
  4. Interactions with Surrounding Features 3 - Breakpoints
    1. Place breakpoint in a method
    2. Collapse the method fold
    3. Reach the breakpoint by a debugger session
      - The breakpoint is not visible when the method containing it is collapsed.
      - The code fold must be expanded when debugger session reaches it.
  5. Interactions with Surrounding Features 4 - Find & Replace
    1. Search for a text that is inside some folded code
    2. Try to replace some text that is inside collapsed fold
    • EXPECTED RESULT: If search finds the string inside collapsed fold, that fold is expanded
  6. Background/Foreground color
    1. Invoke Tools|Options|Fonts&Colors|Highlighting
    2. Select "Code Folding" in Category list and change background and foreground color settings
    3. Select "Code Folding Bar" in Category list and change background and foreground color settings
    4. Confirm the Options dialog with OK button
    • EXPECTED RESULT: Colors for collapsed code fold and for the [+]/[-] signs must respect settings.

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo