如何 运行 从命令行而不是 Intellij IDEA 进行 JUnit 测试?
How to run JUnit tests from the command line instead of Intellij IDEA?
我在测试文件夹中有一个带有 Junit5 测试的 Intellij IDEA 项目。如果我使用 IDEA 的 GUI 单击播放按钮,则测试有效。但是,我需要能够使用命令行来 运行 这些测试,但我不知道如何。
给定项目文件夹,我如何在不依赖 IDEA 的 GUI 的情况下使用命令行 运行 测试文件夹中的测试?
您可以使用 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.
要 运行 一个包中的所有测试,您可以 运行:
java -jar junit-platform-console-standalone-1.5.2.jar
-cp 'build/classes/java/test'
--select-package com.mypackage
您可以阅读 MKyong 的教程进行介绍:JUnit 5 ConsoleLauncher examples
大多数构建系统都提供测试目标。例如:
- Gradle:
./gradlew test
- 行家:
mvn test
我在测试文件夹中有一个带有 Junit5 测试的 Intellij IDEA 项目。如果我使用 IDEA 的 GUI 单击播放按钮,则测试有效。但是,我需要能够使用命令行来 运行 这些测试,但我不知道如何。
给定项目文件夹,我如何在不依赖 IDEA 的 GUI 的情况下使用命令行 运行 测试文件夹中的测试?
您可以使用 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.
要 运行 一个包中的所有测试,您可以 运行:
java -jar junit-platform-console-standalone-1.5.2.jar
-cp 'build/classes/java/test'
--select-package com.mypackage
您可以阅读 MKyong 的教程进行介绍:JUnit 5 ConsoleLauncher examples
大多数构建系统都提供测试目标。例如:
- Gradle:
./gradlew test
- 行家:
mvn test