Skip to content
Tracks issues for the Squaretest plugin for IntelliJ IDEA
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Squaretest - for IntelliJ IDEA

The Squaretest plugin for IntelliJ IDEA allows you to automatically generate unit tests for your Java source classes. The generated test-classes contain code to construct the instance of the source-class (if needed) and initialize the dependencies to either mocks or reasonable default values. The test-classes include test methods that invoke their corresponding source-methods and compare the returned-values to expected-values.

Create a Test Class for your Java Class

Select Squaretest | Generate Test from the toolbar to create a test-class for your Java source class.

Generate Test Gif

Create a Test Method

Start typing the name of the test-method you want to create to see code-completion suggestions based on the methods in your source class; then select one of the suggested methods to create it.

Generate Test Method Gif


Generate a Test Class for Your Java Class with One Action

Use the configurable keyboard shortcut: ctrl+alt+K on Windows and Linux or cmd+shift+L on OS X to generate a test-class in either Java (1.7+) or Groovy.

The Generated Test Class Contains Appropriate Boilerplate Code

Squaretest automatically generates the following based on your source-class:

  1. Code to construct the instance of the source-class and initialize its dependencies, if needed
  2. A test-method for each public and package-local method in the source-class, containing
    • Local-variables for the arguments required by the method
    • A local-variable for the expected returned-value
    • Code to invoke the method
    • An assertEquals() call or Groovy assertion statement to verify the returned value

Use a Velocity Template to Configure How the Test Classes Are Generated

All aspects of the generated test-classes are determined by an Apache Velocity template. You can use one of the default templates included with Squaretest or create your own template. More...

Includes Default Velocity Templates for Common Test Frameworks

Squaretest includes default Velocity templates for both Java and Groovy for the following test-frameworks and mocking frameworks.

  • JUnit4 with Mockito
  • JUnit5 with Mockito
  • Robolectric3 with Mockito
  • AndroidJUnit4 with Mockito

Detects Design Patterns in the Source Class

All templates included with Squaretest detect and handle the following design-patterns in the source-class.

  • Class with dependencies provided in the constructor (the standard Java component)
  • Class with private, dependency-annotated fields (fields annotated with @Inject or @Autowired)
  • Class with package-local, dependency-annotated fields (common in Android apps using Dagger or Guice).
  • Class with static creator methods like parse(..) or from(..) but no package-visible constructor; i.e. the sealed abstract class and similar patterns
  • Abstract classes in general
  • Class containing only static methods; i.e. the Utils classes.
  • Singleton (traditional and enum)
  • Enums in general
  • Android activity (Robolectric3 and AndroidJUnit4 templates only)

Quick Settings in the Default Templates

All templates included with Squaretest have Quick Settings, or variables set at the top of the file that can be used to set code-style and other settings. The Quick Settings include the following options.

  • Use special prefixes for test-class members containing dependencies and/or mocks
  • Use special prefixes for local-fields containing test-method parameters and/or mocks
  • Customize the name of the member or local-field used to store the instance of the source class.
  • Use static imports for initMocks and related methods
  • Use mocks for mockable parameters whose names end in listener or callback
  • Use custom initialization expressions for dependencies and test-method arguments of certain types. More...

Default Values for Common Types

Squaretest uses default values for certain commonly-used types that you usually don't want to mock; e.g. dependencies and local-fields of type List will be set to Arrays.asList() instead of a mock or null. Squaretest recognizes 150+ default types from the following libraries.

  • The JDK 8
  • Apache Commons Lang 2 and 3
  • Google Guava
  • RxJava

Squaretest also selects default-values based on the libraries present on the test classpath; e.g. dependencies and local-fields of type Executor will use MoreExecutors.directExecutor() from Google Guava if it's available on the test classpath.

Configurable Project-Level and Module-Level Settings

Open Existing Unit-Tests with the Same Keyboard Shortcut

Before saving the generated test-class, Squaretest searches the project for a class with the same or similar canonical-name. If a match is found, Squaretest opens the existing test instead of creating a new one. Similar canonical-name means the canonical-name +/- 's'; e.g. if the test-class is named com.myapp.FooTest, the similar name is com.myapp.FooTests and vice versa. This allows you to jump from a source class to its unit-tests with one keyboard shortcut.

Configure where the Unit-Test Class is Opened

Squaretest can open the generated (or existing) unit-test file in the following ways, configured by the Application Settings.

  • In the same editor window as the source class.
  • In the editor window next to the source class if one is available.
  • In an editor window next to the source class, splitting the editor-window containing the source class vertically to create one if needed.


Please feel free track bugs here and post feedback, questions and feature-requests to the support forum.

Terms and Conditions

By installing and using Squaretest, you agree to the Terms and Conditions.

You can’t perform that action at this time.