First steps for writing tests for a Git plugin


I'm contributing to a plugin which depends on the git4idea plugin. I'd now like to write some basic tests but I absolutely have no idea where and how to start. I read the guides at but, being honest, they are not much of a help to me.

As a very first basic test I'd like to achieve the following:

  1. Call an action provided by the plugin.
  2. Use existing methods (maybe of git4idea) to ensure that e.g. a branch was created.

Could you give me some advice or examples? I already looked at e.g. VcsPlatformTest() but I'm not sure if this is helpful or how I can include this in my testing project.


Official comment

The best would be to extend the GitPlatformTest class (or, for example, a little bit more specific GitSingleRepoTest). Almost all git4idea tests are its inheritors, take a look at their source code to get the idea.

1. Please note that it is not recommended to invoke AnAction directly. Better to test the "backend" code which does actual work after the action is invoked.

2. To check if a branch is created you can do the following: call GitRepository#update() to let the GitRepository re-read information from .git, then check that your branch exists in GitRepository#getBranchesCollection.

Hope this helps. Feel free to ask if you need more details or examples.

Thanks a lot, Kirill. This answer provides a starting point. My plugin uses Gradle. How do I add the necessary dependencies so that I can extend GitSingleRepoTest?


Ah, I've found out that unfortunately, there is no way to use GitPlatformTest at the moment :( We don't distribute our test framework classes, so a plugin can't depend on them. Please follow for updates, the plan is to fix it in 2019.



Ok, thanks for the info. So basically I would need to implement the tests "from scratch"?


Yes, I'm afraid it is so for the moment. You may look and copy paste the code from intellij-community, of course.


Hey all,

I'm sorry to revive this thread but I'm facing the exact same problem as the issue creator.
The artifact mentioned in the youtrack link Kirill posted seems to be no longer available, so I wonder If it's possible to access e.g. GitPlatformTest somehow (or if there is an alternative).


Please sign in to leave a comment.