Testing custom designer editor panel

I have registered my file editor provider in plugin.xml:

<extensions defaultExtensionNs="com.intellij">
  <fileEditorProvider implementation="com.designer.IXMLFileEditorProvider"></fileEditorProvider>
  <fileTypeFactory implementation="com.designer.ixml.IXMLFileTypeFactory"/>
  <lang.parserDefinition language="IXML" implementationClass="com.designer.ixml.IXMLParserDefinition"/>
</extensions>

IXMLFileEditorProvider created IXMLDesignerEditorPanel. When I used Plugin run configuration there are no problems in registering custom provider(IXMLFileEditorProvider) and rendering custom panel (IXMLDesignerEditorPanel).
I have tried to test my custom panel on the same manner as the AndroidDesignerEditorPanel(I have found this test in source code of Intellij IDEA-coummunity edition). But I have faced with problem - root component(RadComponent) of my editor is null.
Does anyone know some tutorials/articles related to testing custom editor panel?

P.S. Tutorial "Writing Tests for Plugins" (https://confluence.jetbrains.com/display/IntelliJIDEA/Writing+Tests+for+Plugins) is not useful in this case.

3 comments
Comment actions Permalink

Please show the setup code for your test.

0
Comment actions Permalink
        setUp();

        
String sdkPath = getTestSdkPath();

        final
TestFixtureBuilder<IdeaProjectTestFixture> projectBuilder = IdeaTestFixtureFactory.getFixtureFactory().createFixtureBuilder(getName());
        myFixture
= JavaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture(projectBuilder.getFixture());
        final
JavaModuleFixtureBuilder moduleFixtureBuilder = projectBuilder.addModule(JavaModuleFixtureBuilder.class);
        final
String dirPath = myFixture.getTempDirPath() + getContentRootPath();
        final
File dir = new File(dirPath);

        if
(!dir.exists()) {
            Assert.assertTrue(dir.mkdirs());
        
}
        tuneModule(moduleFixtureBuilder, dirPath);

        final
ArrayList<MyAdditionalModuleData> modules = new ArrayList<MyAdditionalModuleData>();
//        configureAdditionalModules(projectBuilder, modules);
        
System.setProperty(PlatformUtils.PLATFORM_PREFIX_KEY, "Idea");
        myFixture
.setUp();
        myFixture
.setTestDataPath(getTestDataPath());
        myModule
= moduleFixtureBuilder.getFixture().getModule();

        
createManifest();

        myFacet
= addAndroidFacet(myModule, sdkPath, getPlatformDir(), true);
        myFixture
.copyDirectoryToProject(getResDir(), "res");

        myAdditionalModules
= new ArrayList<Module>();

        for
(MyAdditionalModuleData data : modules) {
            final Module additionalModule = data.myModuleFixtureBuilder.getFixture().getModule();
            myAdditionalModules
.add(additionalModule);
            final
AndroidFacet facet = addAndroidFacet(additionalModule, sdkPath, getPlatformDir());
            
facet.setLibraryProject(data.myLibrary);
            final
String rootPath = getContentRootPath(data.myDirName);
            myFixture
.copyDirectoryToProject("res", rootPath + "/res");
            myFixture
.copyFileToProject(SdkConstants.FN_ANDROID_MANIFEST_XML,
                    
rootPath + '/' + SdkConstants.FN_ANDROID_MANIFEST_XML);
            
ModuleRootModificationUtil.addDependency(myModule, additionalModule);
        
}

        if (RenderSecurityManager.RESTRICT_READS) {
            // Unit test class loader includes disk directories which security manager does not allow access to
            
RenderSecurityManager.sEnabled = false;
        
}


I use setup code from LayoutEditorTestBase (parent of the AndroidDesignerEditorPanelTest).

I have found some strange thing - LayoutLibrary can't create new instance of "com.android.layoutlib.bridge.Bridge"(Object bridgeObject = constructor.newInstance(); throw exception) when I start unit test but this promlem does not reproduce when I start plugin. In both cases I have used the same classpath of module(plugin module classpath).

0
Comment actions Permalink

B-) I have done it!!!

The root cause was in "android.jar" in classpath. In LayoutLibrary we add an "icu4j.jar" & "layoutlib.jar" (with implementation of android classes) and then load "com.android.layoutlib.bridge.Bridge" from "layoutlib.jar". But other classes, used inside Bridge, classloader have taken from "android.jar" that is why I have caught echeption.

0

Please sign in to leave a comment.