DEV Community

Brandon Rozek
Brandon Rozek

Posted on • Originally published at brandonrozek.com on

JUnit Script

Running a JUnit test on the terminal is a little annoying. Here is a quick script to make it easier, make it executable and drop it in ~/.local/bin for easy use.

#!/bin/sh

set -o errexit
set -o nounset
set -o pipefail

JUNIT_PATH="/usr/share/java/junit4.jar"

show_usage() {
    echo "Usage: junit [class file path]"
    exit 1
}

# Check argument count
if ["$#" -ne 1]; then
    show_usage
fi

java -cp "$JUNIT_PATH":. org.junit.runner.JUnitCore "$1"

Enter fullscreen mode Exit fullscreen mode

Replacing JUNIT_PATH with the location of the junit4.jar on your system.

Top comments (0)