How to get the current class name to run mvn test using vim
I'm trying to add a shortcut for mvn test so I can q开发者_JAVA百科uickly get feedback (tdd style) when I'm working in java.
How can you get the name of the current class you are working in to concat .Test so I can do something like !mvn -DfooTest test
Thank you in advance
If you are inside the test class itself or the implementation class -- the vimscript below will run the unit test using mvn test (assuming your test class has the same name as your implementation class + Test)
function RunTest()
let src_dir = finddir('src',';')
exec 'cd' fnameescape(src_dir)
exec 'cd ..'
let objName = expand('%:t:r')
let class = "mvn -Dtest=" .objName
if match(objName, "Test") == -1
let class = class . "Test"
endif
let class = class . " test"
echo class
echo system(class)
cd -
endfunction
精彩评论