Skip to content

Instantly share code, notes, and snippets.

@linux-china
Created January 5, 2024 01:39
Show Gist options
  • Save linux-china/1576d3b2af252f394ba6d208b28c1570 to your computer and use it in GitHub Desktop.
Save linux-china/1576d3b2af252f394ba6d208b28c1570 to your computer and use it in GitHub Desktop.
Run JUnit 5 Tests with JBang
//usr/bin/env jbang "$0" "$@" ; exit $?
//JAVA 21
//DEPS org.junit.jupiter:junit-jupiter-engine:5.10.1
//DEPS org.junit.platform:junit-platform-console:1.9.3
//DEPS org.assertj:assertj-core:3.25.1
package com.example;
import org.junit.jupiter.api.Test;
import org.junit.platform.console.options.CommandLineOptions;
import org.junit.platform.console.tasks.ConsoleTestExecutor;
import org.junit.platform.engine.discovery.DiscoverySelectors;
import java.io.PrintWriter;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
public class JUnit5ExampleTest {
@Test
public void testSpike() {
assertThat(1 + 1).isEqualTo(2);
}
public static void main(String[] args) throws Exception {
CommandLineOptions options = new CommandLineOptions();
options.setSelectedClasses(List.of(DiscoverySelectors.selectClass(JUnit5ExampleTest.class)));
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