How to use JavaCodeInsightFixtureTestCase

Answered

Hi,

I've been trying to create a very simple test case for my plugin but no luck so far.

This is my test case:

@TestDataPath("testData/")
public class FormatterActionHandlerTest extends JavaCodeInsightFixtureTestCase {
    public void testBasic() {
        Editor editor = myFixture.getEditor();
        myFixture.copyFileToProject("Simple.java");
        myFixture.copyFileToProject("testData/Simple.java");
    }
}

When I run it I get two problems:

1) editor variable is always null
2) junit.framework.AssertionFailedError: Cannot find source file: 'Simple.java'. getTestDataPath()='C:/Andre/.IntelliJIdea/system/plugins-sandbox/test'. getHomePath()='C:/Andre/.IntelliJIdea/system/plugins-sandbox/test'.

My project structure looks like this:

My Plugin
+--- src
+--- testSrc
   +--- FormatterActionHandlerTest.java
+--- testData
   +--- Simple.java

I tried to override getBasePath() and getTestDataPath() methods and use PluginPathManager.getPluginHomePath() but it didn't work either...   

I'm running the tests from my plugin project... Am I missing something?

Thanks,
Andre

1 comment
Comment actions Permalink

Hi Andre,

I know this does not solve all of your problems, but I recently ran into the same problem. I was able to work around it by using

myFixture.addClass("public class MyClass { ... /* your code */ }");

at the beginning of a test method that uses that class, instead of trying to load it from my test resources.

0

Please sign in to leave a comment.