WindBreeze
WindBreeze

Reputation: 223

How to run JUnit tests from the command line instead of Intellij IDEA?

I have an Intellij IDEA project with Junit5 tests in the tests folder. The tests works if I click on the play button using IDEA's GUI. However, I need to be able to use the command line to run those tests but I don't know how.

Given the project folder how can I use the command line to run the tests in the tests folder without relying on IDEA's GUI?

Upvotes: 2

Views: 4665

Answers (2)

EricSchaefer
EricSchaefer

Reputation: 26410

Most build systems provide test targets. For example:

  • Gradle: ./gradlew test
  • Maven: mvn test

Upvotes: 0

Ortomala Lokni
Ortomala Lokni

Reputation: 62733

You can use the JUnit ConsoleLauncher:

The ConsoleLauncher is a command-line Java application that lets you launch the JUnit Platform from the console. For example, it can be used to run JUnit Vintage and JUnit Jupiter tests and print test execution results to the console.

To run all tests from a package you can run:

java -jar junit-platform-console-standalone-1.5.2.jar 
      -cp 'build/classes/java/test' 
      --select-package com.mypackage

You can read the tutorial from MKyong for an introduction: JUnit 5 ConsoleLauncher examples

Upvotes: 1

Related Questions