Create JUnit tests more productively with Symflower
Symflower fully supports you when writing Java tests with JUnit 4 and JUnit 5. There are two ways to use Symflower to streamline your unit testing activities:
- Instantly generate boilerplate testing code Symflower’s smart test template functionality enables you to instantly generate all the boilerplate code you need for writing a JUnit test.
- Generate full unit test suites You can also rely on Symflower to create complete unit tests based on your implementation.
Generating boilerplate testing code
To create the boilerplate of a JUnit test, simply right-click inside the function or method you want to test and click on
Symflower: Add Unit Test for Function. Alternatively, you can also use the editor action
Symflower: Add Unit Test for Function or the shortcut of the editor’s action.
Symflower then immediately generates all the boilerplate for a single test case, including the initialization, call and asserts, and makes your cursor jump to the right spot to start typing your test scenario. This makes writing tests during test-driven development (TDD) especially swift and productive.
Generate full unit test suites
To generate a full unit test suite based on your current source code, simply right-click inside the function or method you want tests for and click on
Symflower: Generate Unit Tests for Function. Alternatively, you can also use the editor action
Symflower: Generate Unit Tests for Function or the shortcut of the editor’s action.
Symflower then generates a full unit test suite for every unique path, if your source code is supported. This suite includes cases for problems such as thrown but unhandled exceptions, which allows you to instantly reproduce and fix unexpected behavior right in your editor.
Changing the test framework
Symflower automatically detects which test framework you are using. However, due to your particular setup, you may run into some problems with this automatic detection. If you encounter such an issue, please let us know by either opening a bug report on our public issue tracker or just write us an email to email@example.com . As a workaround, you can always force using a specific test framework by changing the settings for your project, editor, or via a command line option. The following sections will discuss these configurations steps.
Android Studio, GoLand and IntelliJ configuration
To change the default test framework for Java, go to the settings view of the Symflower extension: Main menu -> File -> Settings -> Click on Tools -> Symflower. There you can change the
Test Framework for Java from
automatic to either JUnit 4 or JUnit 5.
VS Code configuration
To change the default test framework for Java, go to the settings view of the Symflower extension: Press CtrlShiftP -> Type in
settings -> Choose either the user or the workspace settings -> In the settings view, filter for
symflower. There, you can change the
Test Framework for Java from
automatic to either
JUnit 4 or
Symflower CLI provides the
--java-test-framework option to change the default test framework to either JUnit 4 or JUnit 5, e.g.
symflower --java-test-framework JUnit4 sets the test framework for Java to JUnit 4.
To set a default test framework for your whole project no matter if you are using the CLI or which editor you are using, create the directory
.symflower in the root directory of your project, and create the file
settings.json in there with the following content:
This configuration changes the default test framework for Java to JUnit 4. Alternatively, you can also use
JUnit5 as a value for JUnit 5.
Please note that the project configuration can be overwritten by using the CLI option or setting an explicit framework in your editors.