What is the recommended approach for testing DocumentationProvider I've added for my language support plugin?



I've added a documentation provider for my language support plugin: https://github.com/xonixx/intellij-awk/blob/main/src/main/java/intellij_awk/AwkDocumentationProvider.java. All seems to work good, I can test it manually in IDE. 

But I would like to have this functionality unit-tested. I would prefer the E2E test of type: "take a sample source code and make sure that for the element under cursor the Ctrl-Q shortcut shows expected data". Lots of similar functionlity can be tested using CodeInsightTestFixture but I don't see any means of testing the documentation logic there.

What can be a recommended approach here? 

Comment actions Permalink

Hi, Volodymyr!

You may try accessing your provider with:

DocumentationProvider provider = DocumentationManager.getProviderFromElement(element);

and then assert the returned value i.e., from

provider.getQuickNavigateInfo(docElement, getOriginalElement())

Check ThemeJsonDocumentationProviderTest test as an example.

Comment actions Permalink

Thank you Jakub!

This indeed seems to be very close to what I need.

Upd. Was able to add the tests I needed: https://github.com/xonixx/intellij-awk/blob/main/src/test/java/intellij_awk/AwkDocumentationProviderTests.java


Please sign in to leave a comment.