UnitTesting IntelliJ plugins : how to invoke an action ?

Hello,

I'm writing a Vcs plugin (or rather hacking on the hg4idea plugin), and would like to programmatically invoke the "Version Control" > "Update Project" action. How can I do that ?

My TestCase extends from AbstractVcsTestCase, but that does not seem to provide anything to do this.

Thanks for any help,
Willem

5 comments
Comment actions Permalink

I know it's been 4 years, but.... bump!

I'd be really glad to hear more about how you got it working.

Also, if there are alternative ways to test VCS related stuff (trigger "mock" commits and updates from tests) nowadays, intellij experts, please feel free to pitch in :)

Thank you in advance,
Stas

0
Comment actions Permalink

Well, answering to the original message: although an action can be called programmatically, it is not the best idea to do it. Better just test the code which the action calls. E.g. call the HgUpdateEnvironment directly, as the Update Project action does.

As about your question, Stas, we don't mock commits in IDEA to test VCS integration stuff. We create a real hg repository, perform real commits, etc. Such tests are not so quick as mocked up unit tests would be, but they have their own advantages. For example of such tests look into the HgPlatformTest & its subclasses (actual tests).

0
Comment actions Permalink

Hello Kirill,

Thanks for taking the time to reply.

That's an interesting approach. Could you say a few words on how you actually trigger these commits/updates/etc. from a test (i.e., the API being used)?
Is it done progremmatically or do you use some kind of a user activity simulator on the GUI level?

Thanks a lot,
Stas

0
Comment actions Permalink

We do it programmatically.
Most of our tests are functional with a real IDEA project inside (only GUI and some specific components are mocked), therefore we've got an instance of Project and all other components and services. Thus we can e.g. call ProjectLevelVcsManager.getInstance().getVcsFor/other-get*Vcs-methods to get an instance of the AbstractVcs, and then, say, call AbstractVcs#getCheckinEnvironment to achieve the instance of CheckinEnvironment. With it we can call commit().

0
Comment actions Permalink

Great, thanks a lot!

(On a related note, I've posted a question regarding the VCS api in the Open API and Plugin Development discussion section which corresponds with your answer, any chance I could trouble you with taking a look? :))

0

Please sign in to leave a comment.