Replace serviceImplementation in IdeaTestCase

Hi I'm trying to run a test using IdeaTestCase, and I want to use a Mock of a service I usually use.

Is there anyway to change the serviceImplemenation for a given service interface during testing (with IdeaTestCase because I want plugin.xml to load other things)?

For example I'd like to do something like :

public class SomeTest extends IdeaTestCase {
   ...


   public void testDoSomething {
     ServiceManager.replaceService(MyService.class, MyServiceTestImpl.class)


     ....
   }
}

2 comments
Comment actions Permalink

I'm really adding some validation for a KeyedExtension point.  I want to make sure the correct single extension is loaded but I can't run the test because some instances of the ExtensionPoint use a service that I need to mock during testing.

0
Comment actions Permalink

You can use com.intellij.testFramework.UtilKt#registerServiceInstance, do not forget to store original service instance in setUp and restore it in tearDown.

0

Please sign in to leave a comment.