Testing an AppCode Intention Plugin


I would like to write some tests to support a plugin that I am building but the documentation refers to classes which the AppCode SDK doesn't seem to contain. I'm using AppCode specific APIs so I can't use a different SDK.

I would just like to test that applying my intention will change the PSI tree as I expect. Does anyone know how to get started with writing a test for an AppCode plugin?

Comment actions Permalink

Sean, we don't have publicly available framework to test AppCode plugins with.

But you can build your own: Inherit from PlatformTestCase, in setUpProject  open a test xcode project using ProjectUtil.openOrImport(xcpdeprojFile, null, true), then test as usual (see CodeInsightTestFixture)

Comment actions Permalink

Thanks Anton. I'll give it a go :)

Comment actions Permalink

I've tried what you suggested with some success but I've run into a couple of problems.

I have inherited from PlatformTestCase and overridden setUpProject where my code looks like this:

Project project = ProjectUtil.openOrImport(testDataDir + "/MockGeneratorTest/MockGeneratorTest.xcodeproj", null, true);
TestFixtureBuilder<IdeaProjectTestFixture> projectBuilder = IdeaTestFixtureFactory.getFixtureFactory().createFixtureBuilder(name);
myFixture = IdeaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture(projectBuilder.getFixture());

From the examples I've seen I should be doing something like this:

PsiFile file = myFixture.configureByFile("MyFile.swift");
IntentionAction action = myFixture.findSingleIntention("My intention");
() -> action.invoke(myFixture.getProject(), myFixture.getEditor(), psiFile));

I've checked myFixture.getAvailableIntentions() and it is always empty (even though my plugin always returns true for isAvailable).

I assume the problem is that I'm creating a project using ProjectUtil.openOrImport but the fixture is creating its own project and when I use configureByFile() it is configuring it to the wrong project.

So my question now is, how do I get my CodeInsightTestFixture to work with my opened project? Or, if I'm going about this wrong, is there a small example you could show me to help get me started?

Note: I've tested the plugin manually and I can run my intention.

Many thanks!

Comment actions Permalink

Sean, apologies for the delay, was on vacation.

I think you need to add the file to the xcode project first. Try something like

 PBXProjectFile project = XcodeMetaData.getInstance(getProject()).getWorkspaceProjects().get(0);
PBXProjectFileManipulator manipulator = project.getManipulator();

List<PBXTarget> targetList = project.getTargets(null);
PBXTarget[] targets = targetList.toArray(new PBXTarget[targetList.size()]);

PBXGroup mainGroup = project.getProjectObject().getMainGroup();
manipulator.addFile(file.getPath(), targets, mainGroup, false);


BTW, here is a request for AppCode testing framework OC-15202 (not in short term plans though).


Please sign in to leave a comment.