How do I register a language with a test fixture for parser, etc. tests?


I'm working on migrating my plugin tests from PlatformLiteFixture to the IdeaTestFixtureFactory framework. I have simple platform tests working, but am now trying to figure out how to get tests that require parsing a language to work (so using PsiManager.getInstance(project).findFile(file) will return a PsiFile of the parsed file in the specified language).

What is the recommended way to register a language extension, parser definition, and AST factory using the IdeaTestFixtureFactory framework? Are there any examples of this being used? How do I register the language file type (see below for details)?

# Registering File Types

I've tracked down the current issue to file.getFileType() in FileManagerImpl#createFileViewProvider. This is because the filetype is not registered. However, if I do:

val app = ApplicationManager.getApplication()
app.registerServiceInstance(, MockFileTypeManager(fileType))

Then the file.getFileType() call still ends up using FileTypeManagerImpl instead of the mock class (additionally, HeavyIdeaTestFixtureImpl is casting to FileTypeManagerImpl, making it hard to replace that with a mock implementation). -- How do I register/customize services on the fixture's application instance?

I can't use registerFileType as that is deprecated.

So do I need to make use of the FileTypeBean extension point? If so, where and when do I register those, as I need an application instance to register the EP on and the associated FileTypeBean instances, but need to do it before the FileTypeManagerImpl is registered.

Comment actions Permalink


If you're implementing custom language support, you have to specify and implement these in your plugin.xml file. Check the Custom Language Support pages in our SDK Docs.

There's also a dedicated tutorial for testing custom languages available: Testing a Custom Language Plugin.

Comment actions Permalink

I have a plugin.xml file in my main package for IntelliJ support. I've split the implementation into different packages, and am running the tests in those sub-packages.

So does that mean that I need to have a plugin.xml file for the new test fixture classes to work?

Is there a way to customize this like could be done with the PlatformTestCase class (i.e. calling register functions on the application and project)? -- Different tests are pulling in different parts of my project from the different packages, including language support.

I would also like to control which parts of the plugin I pull into the tests so I know what I am testing -- e.g. so I can test a specific code completion provider in isolation instead of all of them.

My parser tests are currently using ParsingTestCase and that is working. I would like to move them to the fixture model to remove the reliance on the JUnit 4 support, which I'm currently disabling by making the test classes private. Moving them to the fixture model would also make them consistent. Is there no fixture-based parser pattern for JUnit 5 only tests?

Comment actions Permalink

Reece, sorry for the late reply – this thread got lost in a queue. Did you manage to handle it?

Comment actions Permalink

Not yet. I tried experimenting with the light and heavy fixtures a while back, but had various issues getting it working. I haven't re-looked at this yet.

I'll probably initially modify the tests to not rely on the JUnit 4 derived classes (i.e. UsefulTestCase) and then look to see if it is possible to get it working with the fixtures framework.

It would be useful to have documentation on more advanced usages of the fixture test framework -- e.g. setting up enough for parsing, and then registering the parser definition(s) you need for testing, like can be done with the JUnit 4 based test classes.


Please sign in to leave a comment.