Skip to content

Instantly share code, notes, and snippets.

@Slayug
Last active October 15, 2021 16:45
Show Gist options
  • Save Slayug/d017c5d97b4f014f6b2648e8ca06b31b to your computer and use it in GitHub Desktop.
Save Slayug/d017c5d97b4f014f6b2648e8ca06b31b to your computer and use it in GitHub Desktop.
Running JUnit 5 Tests programmatically
/**
* You need the following dependencies in your classpath:
* junit-platform-console
* junit-platform-launcher
* junit-jupiter-engine
**/
import org.junit.platform.console.options.CommandLineOptions;
import org.junit.platform.console.options.Details;
import org.junit.platform.console.options.Theme;
import org.junit.platform.console.tasks.ConsoleTestExecutor;
import java.io.PrintWriter;
import java.util.Collections;
public class JUnit5Runner {
public static void main(String[] args) throws Exception {
CommandLineOptions options = new CommandLineOptions();
options.setSelectedPackages(Collections.singletonList("io.toast.test"));
options.setBannerDisabled(true);
options.setTheme(Theme.UNICODE);
options.setDetails(Details.TREE);
new ConsoleTestExecutor(options).execute(new PrintWriter(System.out));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment