开发者

How to get the current class name to run mvn test using vim

开发者 https://www.devze.com 2023-02-26 04:02 出处:网络
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.

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
0

精彩评论

暂无评论...
验证码 换一张
取 消