Introducing the KotlinTest IntelliJ IDEA Plugin
I think it is fair to say that when it comes to Kotlin specific test frameworks, the two most popular are KotlinTest and Spek. Indeed KotlinTest is used by prominent open source projects such as Arrow and from personal experience I know it is popular at large banks like Deutsche Bank and Barclays.
However it seems many projects still choose to stick with the perennially popular JUnit or use the basic but functional kotlin.test classes that ship with the standard library.
Perhaps one of the reasons is that until now KotlinTest has lacked first class support for the framework from within IDEA.
Test frameworks for other languages — such as ScalaTest, Specs2, and Spock — have benefited from first class support by Jetbrains. However, thus far, KotlinTest has been excluded from the fun. Well wait no longer, we’ve taken on the task ourselves, and the KotlinTest team is proud to present the first release of an IDEA plugin!
The plugin is easily installed via the standard Jetbrains plugin repository available inside your IDE.

Note: The plugin requires at least version 3.3.1 of KotlinTest.
Run Icons
Once installed (and with IDEA restarted), the first thing you will notice is that each test case inside a Spec
has it’s own run gutter icon. Here is an example for the popular WordSpec
style.

Clicking on any of the run icons will bring up the standard run / debug popup which, when launched, will run that test as well as tests under that path. In other words, any tests defined inside that scope will also be executed.

It’s a great way to run just the particular test or test group you are working on. Just what you’ve been used to with JUnit.
These icons are generated for all spec styles. For instance, here is a screenshot from another spec style — the FeatureSpec
.

Create Test Dialog
Maybe you are already familiar with create test dialog. If not, this is accessed via ctrl+shift+T on a class name and brings up a little dialog showing current tests for this class as well as the option to create a new test file.

When this option is chosen then something like the following dialog should appear with a couple of options.

You can decide if you want the setup
/ teardown
functions automatically inserted. In KotlinTest these are called beforeTest
and afterTest
respectively.
Here’s an example of a test file automatically created with both of those life-cycle methods added. The init block has been created as well,ready for the placement of tests.

The plugin will also add the shouldBe
import which is the most commonly used assertion function.
When using this dialog, you are also given the option to generate test stubs for the functions present in the class under test.

If you select some of those functions then click OK, the generated test file will have blank tests ready to go. For example:

The generated tests reflect the testing style you choose (the parent class), so if you have selected say FeatureSpec
, then the tests will be generated in a way that is compatible with that style.

Jump to Source
Once a test has been executed, there is the option to jump to the source of any test — pass or fail.

Selecting this option opens that particular test in the editor.
Intentions
There’s also support for some basic intentions (intentions are what IDEA calls the context aware suggestions it makes). These include the ability to surround statements with assertSoftly, add exception handling assertions, and to enable / disable a test.
Highlight some code, and then bring up the suggestions window (alt+enter by default, or click the light bulb) and you will see the options for the aforementioned intentions.

Choosing one will result in the highlighted statements (the full lines) being placed inside a lambda within the applicable function.


The other intention I want to highlight (excuse the pun) is to quickly disable/enable a test by using the bang functionality.
Place the caret in a test name string, and then bring up the suggestions dialog. You will see an option to add/remove the bang.

For those who don’t know — any tests that are prefixed with !
are automatically skipped (see full details in this blog post about half way down). This is a useful feature when you want to run an entire Spec except for one or two tests as a temporary measure.
Choosing this intention will update the test name as so:

Choosing the intention again will remove the !
.
In conclusion, with this step change in the user experience coupled with the ability to nest tests in whatever style you deem fit; the largest Kotlin specific assertion library; and tons of other features — I’d argue that there’s never been a better time to switch to KotlinTest.