Plugin Testing (Windows)
Hi all,
I've just been following some of the guides on running tests and i'm hitting some issues;
This is currently my test file
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
import org.junit.Assert;
public class BasicTest extends LightCodeInsightFixtureTestCase {
public void testCompletion() {
Assert.assertTrue(true);
}
}
And these are some of the errors which I seem to get; It seems to be somewhat non-deterministic however
java.io.FileNotFoundException: Native filesystem .dll is missing, home: [Path to IDEA version settings]
I have also been getting these errors too; Sometimes the required plugin will be different, for instance sometimes 'com.intellij.javaee' and sometimes 'JavaScript';
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
ERROR: Problems found loading plugins:
<br>Plugin "JSF Support" was not loaded: required plugin "JavaScript" not installed.<br><br><a href="disable">Disable JSF Support</a><br><a href="edit">Open plugin manager</a>
java.lang.Throwable
at com.intellij.openapi.diagnostic.Logger.error(Logger.java:54)
at com.intellij.ide.plugins.PluginManager.b(PluginManager.java:323)
at com.intellij.ide.plugins.PluginManager.a(PluginManager.java:238)
at com.intellij.ide.plugins.PluginManager.initPlugins(PluginManager.java:120)
at com.intellij.openapi.application.impl.ApplicationImpl.d(ApplicationImpl.java:402)
at com.intellij.openapi.application.impl.ApplicationImpl.<init>(ApplicationImpl.java:239)
at com.intellij.openapi.application.ex.ApplicationManagerEx.createApplication(ApplicationManagerEx.java:39)
at com.intellij.idea.CommandLineApplication.<init>(CommandLineApplication.java:58)
at com.intellij.idea.CommandLineApplication.<init>(CommandLineApplication.java:52)
at com.intellij.idea.IdeaTestApplication.<init>(IdeaTestApplication.java:34)
at com.intellij.idea.IdeaTestApplication.getInstance(IdeaTestApplication.java:48)
at com.intellij.testFramework.LightPlatformTestCase.initApplication(LightPlatformTestCase.java:154)
at com.intellij.testFramework.fixtures.impl.LightIdeaTestFixtureImpl.setUp(LightIdeaTestFixtureImpl.java:51)
at com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl$16.run(CodeInsightTestFixtureImpl.java:1090)
at com.intellij.util.ui.UIUtil.invokeAndWaitIfNeeded(UIUtil.java:1987)
at com.intellij.testFramework.UsefulTestCase.edt(UsefulTestCase.java:272)
at com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl.setUp(CodeInsightTestFixtureImpl.java:1086)
at com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase.setUp(LightCodeInsightFixtureTestCase.java:69)
at junit.framework.TestCase.runBare(TestCase.java:132)
at com.intellij.testFramework.UsefulTestCase.defaultRunBare(UsefulTestCase.java:281)
at com.intellij.testFramework.UsefulTestCase$3.run(UsefulTestCase.java:293)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:241)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:733)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:703)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
java.lang.AssertionError: Problems found loading plugins:
<br>Plugin "JSF Support" was not loaded: required plugin "com.intellij.javaee" not installed.<br><br><a href="disable">Disable JSF Support</a><br><a href="edit">Open plugin manager</a>
at com.intellij.testFramework.LoggedErrorProcessor$1.processError(LoggedErrorProcessor.java:35)
at com.intellij.testFramework.TestLogger.error(TestLogger.java:52)
at com.intellij.openapi.diagnostic.Logger.error(Logger.java:54)
at com.intellij.ide.plugins.PluginManager.b(PluginManager.java:323)
at com.intellij.ide.plugins.PluginManager.a(PluginManager.java:238)
at com.intellij.ide.plugins.PluginManager.initPlugins(PluginManager.java:120)
at com.intellij.openapi.application.impl.ApplicationImpl.d(ApplicationImpl.java:402)
at com.intellij.openapi.application.impl.ApplicationImpl.<init>(ApplicationImpl.java:239)
at com.intellij.openapi.application.ex.ApplicationManagerEx.createApplication(ApplicationManagerEx.java:39)
at com.intellij.idea.CommandLineApplication.<init>(CommandLineApplication.java:58)
at com.intellij.idea.CommandLineApplication.<init>(CommandLineApplication.java:52)
at com.intellij.idea.IdeaTestApplication.<init>(IdeaTestApplication.java:34)
at com.intellij.idea.IdeaTestApplication.getInstance(IdeaTestApplication.java:48)
at com.intellij.testFramework.LightPlatformTestCase.initApplication(LightPlatformTestCase.java:154)
at com.intellij.testFramework.fixtures.impl.LightIdeaTestFixtureImpl.setUp(LightIdeaTestFixtureImpl.java:51)
at com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl$16.run(CodeInsightTestFixtureImpl.java:1090)
at com.intellij.util.ui.UIUtil.invokeAndWaitIfNeeded(UIUtil.java:1987)
at com.intellij.testFramework.UsefulTestCase.edt(UsefulTestCase.java:272)
at com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl.setUp(CodeInsightTestFixtureImpl.java:1086)
at com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase.setUp(LightCodeInsightFixtureTestCase.java:69)
at com.intellij.testFramework.UsefulTestCase.defaultRunBare(UsefulTestCase.java:281)
at com.intellij.testFramework.UsefulTestCase$3.run(UsefulTestCase.java:293)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:241)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:733)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:703)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
Hopefully there's an easy solution for these problems! :)
Cheers
Please sign in to leave a comment.
Just created a new VirtualMachine with Ubuntu and I've had no problems with running the above test.
I'm assuming this is a Windows specific issue then :)
Edit - I was able to reproduce the second error of plugins within Ubuntu still.
I have switched to using a Fixture class, which does not tie me to a specific testing framework, as per the testing documentation
It seems that manually setting the platformPrefix changes the loading of plugins, which stops the JavaScript/Javaee plugin exceptions
System.setProperty(PlatformUtils.PLATFORM_PREFIX_KEY, "PlatformLangXml");
There are comments about what this does specifically here
Unfortunately that still led me to a null pointer exception. Hopefully there's a work around for this too :)
Just trying to debug the null pointer exception now;
And it seems that a method call to JavaSdk.getInstance() is returning null.
I've set a breakpoint within the ComponentManagerImpl class; but for some reason the debugger isn't picking up the field 'myInitializedComponents' instance correctly.
I've attached a screenshot of that, as I'm not sure if that's a bug within IntelliJ or not
Hopefully someone knows about some of the inner workings of this and can point me in the right direction :)
Attachment(s):
InteliJ-SDK-Debug.png
Please make sure to pass -Didea.home.path pointing to your local IntelliJ Community project's path (see com.intellij.testFramework.IdeaTestUtil#getPathForJdkNamed)
Brilliant suggestion Yann! It might be worth adding that information to the testing documentation, possibly under the 'Tests and Fixtures' section, as that section currently talks about being able to use Custom test runners
That now brings me back to the first error I posted, shown below:
Which I certainly consider to be progress :)
Cheers
It took me a while to find this post from Google http://devnet.jetbrains.com/thread/441514, and it offered a possible solution for the above exception.
However that brings back the original NullPointerException JDK at at com.intellij.testFramework.IdeaTestUtil.getMockJdk17
This is the relevant code from IdeaTestUtil
public static Sdk getMockJdk17(@NotNull String name) { return JavaSdk.getInstance().createJdk(name, getMockJdk17Path().getPath(), false); }The call to getMockJdk17Path().getPath() reoslves to C:\Users\alan\.IntelliJIdea12\system\plugins-sandbox\test\community\java\mockJDK-1.7 - Which as far as I can tell is the random path that it plans to create a mock JDK at.
The JavaSdk.getInstance() method returns null however, which results in the NullPointerException.
And as attached to my previous post, I can not inspect the getter code for the Sdk for some reason; potentially due to a bug within IntelliJ's variable inspector.
I am currently running with the following JVM args
IntelliJ doesn't seem to be picking up the project type to be of type PLUGIN_MODULE... I'll have to investigate this a bit more it seems :)
I have still not been able to resolve these issues; However I can definitely confirm that these problems are specifically related to instantiating the test fixture from CucumberJVM.
The initial problem of not being able to find the Windows dll has been fixed by the previously reference post here
So for all intenstive purposes the original question regarding Windows issues has been answered;
However the tests still do not run within the context of CucumberJVM. I have attached an example project showing that issue here
Cheers
Alan
Hi Alan,
The Mock JDK is per project, so IdeaTestUtil.getMockJdk17() returns one that's good for the community plugin. For your own plugin, you'll have to copy the mock JDK files somewhere in your plugin and then you can point to them by overriding getProjectJDK in your test case. Some random snippets from my plugin from a test base class:
Base test class:
private static String JDK_HOME = TestUtils.getMockJdk();
@Override
protected Sdk getProjectJDK() {
return JavaSdk.getInstance().createJdk("java sdk", JDK_HOME, false);
}
TestUtils.java:
public static String getMockJdk() {
return getTestDataPath() + "/mockJDK";
}
That should work.
Cheers,
Colin
Hi Collin,

Thanks for the reply!
I have just switched over to the test class you suggested, but i'm still hitting issues.
The main problem is that `JavaSdk.getInstance()` actually returns null, which then results in a NPE when 'createJdk("java sdk", JDK_HOME, false)' is called
Do you happen to know how they might be happening? :)
Here's a screenshot for clarity;
Are there any reasons why this might happen?
Cheers
Alan
Attachment(s):
CucumberTestingNPE.png
Hmm, I'm not sure about that to be honest - which test class are you using? Mine is derived from LightPlatformCodeInsightTestCase.
The main difference is that i'm trying to kick this off from CucumberJVM you see :)
I've got an example project here http://devnet.jetbrains.com/servlet/JiveServlet/download/5490514-18339/untitled.zip (from the post http://devnet.jetbrains.com/message/5490385#5490514)
You can trigger the test by right clicking HelloWorld.feature and clicking run Feature.
That will fire the @Before method in the World class, which then tries to instantiate CucumberLightFixture (LightCodeInsightTestCase) class, and it's there that the NPE is fired when trying to get the mock sdk :(
Ok, I see - so you're not actually needing JUnit for your tests at all, and I think you should be using test fixtures instead (which is what I do for Clojure testing). Sorry, I can't actually run your example, I'm only on the community edition right now.
In your @Before method, do something like the following:
public class World {
public static CucumberLightFixture cucumberLightFixture;
private static String testDataPath = null;
private JavaCodeInsightTestFixture fixture;
@Before
public void setUp() throws Exception {
System.out.println("Attempting to setUp World");
IdeaTestFixtureFactory fixtureFactory = IdeaTestFixtureFactory.getFixtureFactory();
LightProjectDescriptor descriptor = new DefaultLightProjectDescriptor() {
@Override
public Sdk getSdk()
{
return JavaSdk.getInstance().createJdk("1.7", getMockJdk(), false);
}
};
TestFixtureBuilder<IdeaProjectTestFixture> fixtureBuilder =
fixtureFactory.createLightFixtureBuilder(descriptor);
IdeaProjectTestFixture fixture = fixtureBuilder.getFixture();
JavaTestFixtureFactory javaFixtureFactory = JavaTestFixtureFactory.getFixtureFactory();
fixture = javaFixtureFactory.createCodeInsightFixture(fixture, new LightTempDirTestFixtureImpl(true));
System.out.println("Successfully setUp World for testing");
}
public static String getMockJdk()
{
return getTestDataPath() + "/mockJDK";
}
public static String getTestDataPath()
{
if (testDataPath == null) {
ClassLoader loader = World.class.getClassLoader();
URL resource = loader.getResource("testdata");
testDataPath = new File("testdata").getAbsolutePath();
if (resource != null) {
try
{
testDataPath = new File(resource.toURI()).getPath().replace(File.separatorChar, '/');
}
catch (URISyntaxException e)
{
throw new RuntimeException(e);
}
}
}
return testDataPath;
}
}
Again, I can't test this but that should get you started - you can then use fixture to do all your testing, there are many examples in the CE source code and the JUnit classes use this under the hood.
The CucumberJVM support is actually a free plugin for the CE too! :)
I modified your example code slightly by calling the setUp() method onthe fixture which allowed it to trigger the getSdk() method.
I was also forced to call the code from the EDT, and added the line System.setProperty(PlatformUtils.PLATFORM_PREFIX_KEY, "PlatformLangXml"); - as I still got the odd exceptions I described originally.
Unfortunately this still leds to an NPE in the LightProjectDescriptor's getSdk() method, as the JavaSdk.getInstance() still returns null :(
Thanks again for the help Colin, I feel like we're close to getting this working! :)