StubIndex in unit-test


I'm trying to create a unit-test that relies on a custom StubIndex. In production the code works fine but when unit-testing the stubs are not created for my custom StubIndex.

I'm using:

- LightJavaCodeInsightFixtureTestCase
- myFixture.addFileToProject to create the file that should be indexed
- set breakpoint at IStubFileElementType#getBuilder to check if it gets called

I've also tried changing the type of TestCase but not with any luck. Is there some method that I should call after adding the file with the addFileToProject so that it gets indexed during a unit-test?


Comment actions Permalink

Hi Tim,

Please provide more details.

Do you have your own stubs implementation or do you use existing language stubs? Is "IStubFileElementType.indexStub()" method called? Are index files created in:

  • idea-sandbox/system-test/index/stubs/<index key> - in tests context
  • idea-sandbox/system/index/stubs/<index key> - in IDE context


Comment actions Permalink

It's for my own stubs for a custom language. The indexStub() method is not called. I do see the indexes in the folders you describe but I guess those are created when I run the IDE from my plugin project?

Kr, Tim

Comment actions Permalink

The "system" folder is created for your running IDE instance.

The "system-test" folder is created for headless IDE running during tests. If files are created, then please verify other methods on your stubs methods.

Comment actions Permalink

I removed the system-test folder items and they re-appeared so I the indexing works correct. What is weird is that I still don't see my breakpoint getting hit when running the test at the indexStub() nor the getBuilder().

Anyway, I was using a special method to determine the search scope for the StubIndex which wasn't working correctly in unit-test mode and once fixed the test runs perfectly. Thanks for the very fast responses :)



Please sign in to leave a comment.