How to run all modified JUnit test classes?

雨燕双飞 提交于 2020-06-08 07:09:20

问题


I have an IntelliJ project, versioned in git.

How can I run all JUnit test classes, that I have modified since my last commit?


回答1:


There is Changed Files predefined scope in Project tool window you can use to view all vcs changed files. From there select all JUnit classes and from the context menu create JUnit Run/Debug Configuration which will fill the classes pattern to run automatically.




回答2:


I do not believe there is any 'out of the box' solution to this that you can use. However you could script this in a language of your choice, to find the 'files changed in last commit' you can execute

git diff --name-only HEAD~

HEAD~ is a reference to the 'penultimate' commit, specifying only one commit reference to the git diff command will automatically compare to HEAD which is the latest commit.

You could take the output of this and iterate over it, perhaps if your test classes follow a similar naming scheme to your classes to test execute the tests by specifying a pattern for each file?




回答3:


This library seems to provide similar functionality: https://github.com/rpau/junit4git

This is a JUnit extension that ignores those tests that are not related with your last changes in your Git repository.



来源:https://stackoverflow.com/questions/44136820/how-to-run-all-modified-junit-test-classes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!