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)
....
}
}
Please sign in to leave a comment.
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.
You can use com.intellij.testFramework.UtilKt#registerServiceInstance, do not forget to store original service instance in setUp and restore it in tearDown.