Testing

JUnit 5 online run a test from the gutter

New Maven and Gradle projects come with JUnit 5. Put tests in src/test/java, click the gutter marker or press Ctrl+Shift+F10, and the results appear in a tree with messages and clickable stack traces.

  • JUnit 5 ready
  • Run from the gutter
  • Maven or Gradle
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

class CalculatorTest {
    @Test
    void addsTwoNumbers() {
        assertEquals(5, Calculator.add(2, 3));
    }

    @Test
    void multipliesTwoNumbers() {
        assertEquals(6, Calculator.multiply(2, 3));
    }
}

Click the green marker next to the class or press Ctrl+Shift+F10 with the caret inside it.

Built on the tools Java and Kotlin developers already trust

Java 8 Java 11 Java 17 Java 21 Java 25 Kotlin 2 Maven Gradle Gradle Kotlin DSL Maven Central JUnit 5 Eclipse JDT google-java-format Step debugger
Testing

What you get

Write and run JUnit 5 tests online. Run one test, a class or the whole suite from the gutter and read the results in a tree — Maven or Gradle, Java or Kotlin.

  • JUnit 5 out of the box

    New Maven and Gradle projects include JUnit 5, and the test live template writes a test method for you.

  • One test or all of them

    Run a single method, a class or the whole suite with Run All Tests.

  • Results as a tree

    Passed, failed and skipped tests are grouped by class, with failure messages and stack traces you can click.

  • Maven or Gradle

    Tests run through Maven Surefire or the Gradle test task, exactly as they would on a build server.

  • Add JUnit with a quick fix

    In an older project, put the caret on an unresolved org.junit import and press Alt+Enter.

  • Kotlin tests too

    Tests in src/test/kotlin run the same way, with the same results tree.

How it works

Under the hood

  1. 01

    Where tests go

    Test classes live in src/test/java or src/test/kotlin of a Maven or Gradle project and need JUnit on the test classpath. Plain IntelliJ-style projects run programs but not test suites; create a Maven or Gradle project for tests.

  2. 02

    Reading failures

    A failed assertion shows the expected and actual values in the tree. Click a line of the stack trace to open the test or the code under test at that line, fix it and run the same test again.

FAQ

Questions, answered

Do I need to configure Surefire or the JUnit Platform?

No. New Maven and Gradle projects are created with JUnit 5 and the test runner already configured.

Can I run a single test method?

Yes. Use the gutter marker next to the method or press Ctrl+Shift+F10 with the caret inside it.

Can I debug a failing test?

Reproduce it from an application configuration and set breakpoints in the code under test; the debugger runs Application and JAR configurations.

Do tests have internet access?

No. Tests run in the same isolated sandbox as programs, without network ports or internet access.