Last Updated: February 25, 2016
·
552
· dev360

Run Maven tests like a boss!

This vim shortcut allows you to run your Maven test for the current file you are working in.. INSTANT gratification so that you can spend more time just staring at the compiler output.

/usr/local/bin/mvn_test

#!/bin/bash
class_name=`cat $1 | grep "public class" | cut -d " " -f 3`
current_dir=`pwd`
current_dir=$current_dir"/"

# Find the pom file by going up the directory tree
while true; do
    if [ -f $current_dir"/pom.xml" ]; then break; fi
    export new_dir=`echo $current_dir  | sed "s%\/$%%g" | sed 's/\(.*\/\)[^/]*$/\1/g'`
    if [ "$new_dir" == "$current_dir" ]; then break; fi
    export current_dir=$new_dir
done

(cd $current_dir && mvn test -Dtest=$class_name )

~/.vimrc.local

:map ,mt :w\|!clear && mvn_test %<cr>