DatabaseDriverManager.getInstance returns null in test environment

Answered

Hello,

I recently tried to tidy up my plugin dependencies. I added the current version for the com.intellij.database plugin in my build.gradle.kts

plugins.add("com.intellij.database:221.5080.193")

Before the plugin build was left out.

This caused my tests to fail because DatabaseDriverManager.getInstance() started to return null in test environment. My production code is still working.

Here is a minimal code snippet to reproduce my issue:

final class SomeTest extends BasePlatformTestCase {
@Override
@BeforeEach
protected void setUp() throws Exception {
super.setUp();
}

@Test
public void testSomething() {
Assertions.assertNotNull(DatabaseDriverManager.getInstance());
}
}

Reverting the build.gradle.kts back to

plugins.add("com.intellij.database")

seems to fix the issue but I'm not sure which version is installed then and if the same error will occure just at a later date.

Could you please tell me if this is intended behavior, a bug, or if I did something wrong?

Thanks in advance!

0
4 comments

Hi Nico,

Please check if this plugin is bundled with the IDE you have configured in the intellij extension (intellij.type / intellij.version values). To verify if plugin is bundled, you can check it in the used IDE directory, e.g. /Users/<user_home>/.gradle/caches/modules-2/files-2.1/com.jetbrains.intellij.idea/ideaIC/2022.1/c91a19824ffcb28872ecd2761c83b250f703ff21/ideaIC-2022.1/plugins or in the local installation if you use this approach.

If it is bundled, then you shouldn't specify the version explicitly as the plugin is already in the IDE directory.

If the plugin is not bundled, then make sure it is available and actually downloaded during the tests (check it in the test sandbox directory).

For more details check the "plugins" description in Gradle IntelliJ Plugin doc: https://github.com/JetBrains/gradle-intellij-plugin#intellij-platform-properties.

0

Hey Karol Lewandowski,

thanks for your feedback!

I'm targeting IntelliJ Ultimate for compiling / testing. The plugin is made to be used in PHPStorm, WebStorm and IntellijJ Ultimate.

Checking the plugins directory I can find "DatabaseTools" it includes a database-plugin.jar, so I think this means that it is bundles.

Following your explainationand the linked documentation, that the version should be specified only for not bundled plugins I come to the following result:

intellij {
version.set("2022.1")
type.set("IU")
plugins.add("com.intellij.database")
plugins.add("org.jetbrains.plugins.terminal")
plugins.add("com.jetbrains.php:221.5080.224")
plugins.add("org.jetbrains.plugins.phpstorm-remote-interpreter:221.5080.169")
plugins.add("org.jetbrains.plugins.phpstorm-docker:221.5080.169")
plugins.add("Docker")
}

Could you please confirm, that this is right? With this setup the tests run successfully.

One more little question. If I do only reference classes of "phpstorm-docker" in my plugin code, do I need to add Docker and phpstorm-remote-interpreter, which are sub dependencies, too?

Thanks!

0

Hi Nico,

Yes, regarding the database plugin it is bundled and doesn't require a version as it doesn't have to be downloaded. The setup is correct now.

Regarding the sub dependencies, you should include them in the setup as well, as they all are separate artifacts.

0

Okay, thank you very much, Karol Lewandowski!

0

Please sign in to leave a comment.