Running Android Studio plugin unit tests in Intellij IDEA

I have simple inspection unit test:

class SomeTest : BaseTestCase() {

private fun doTest() {
val tool = MyTool()
doTest("inspections/myToolTest/" + getTestName(true), tool)
}

fun testNullableAnnotation() {
doTest()
}

}

This test throws error:

ERROR: In file: Foo.java
java.lang.NoSuchMethodError: com.intellij.execution.junit.JUnitUtil.isJUnit5TestClass(Lcom/intellij/psi/PsiClass;Z)Z
at com.intellij.execution.junit.JUnit5Framework.isTestClass(JUnit5Framework.java:66)
at com.intellij.testIntegration.JavaTestFramework.isTestClass(JavaTestFramework.java:63)
at com.intellij.codeInsight.TestFrameworksImpl.isTestClass(TestFrameworksImpl.java:38)
at com.intellij.codeInspection.reference.RefClassImpl.initialize(RefClassImpl.java:134)
at com.intellij.codeInspection.reference.RefManagerImpl.lambda$getReference$3(RefManagerImpl.java:503)
at com.intellij.codeInspection.reference.RefManagerImpl.getFromRefTableOrCache(RefManagerImpl.java:571)
at com.intellij.codeInspection.reference.RefManagerImpl.getReference(RefManagerImpl.java:482)
at com.intellij.codeInspection.reference.RefJavaManagerImpl.createRefElement(RefJavaManagerImpl.java:307)
at com.intellij.codeInspection.reference.RefManagerImpl$3.compute(RefManagerImpl.java:490)
at com.intellij.codeInspection.reference.RefManagerImpl$3.compute(RefManagerImpl.java:484)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:859)
at com.intellij.codeInspection.reference.RefManagerImpl.lambda$getReference$2(RefManagerImpl.java:484)
at com.intellij.codeInspection.reference.RefManagerImpl.getFromRefTableOrCache(RefManagerImpl.java:565)
at com.intellij.codeInspection.reference.RefManagerImpl.getReference(RefManagerImpl.java:482)
at com.intellij.codeInspection.reference.RefManagerImpl.getReference(RefManagerImpl.java:467)
at com.intellij.codeInspection.ex.LocalDescriptorsUtil.lambda$static$0(LocalDescriptorsUtil.java:38)
at com.intellij.codeInspection.ex.LocalDescriptorsUtil.addProblemDescriptors(LocalDescriptorsUtil.java:72)
at com.intellij.codeInspection.ex.LocalDescriptorsUtil.addProblemDescriptors(LocalDescriptorsUtil.java:95)
at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.addDescriptors(LocalInspectionsPass.java:167)
at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.doInspectInBatch(LocalInspectionsPass.java:158)
at com.intellij.codeInspection.ex.GlobalInspectionContextImpl.inspectFile(GlobalInspectionContextImpl.java:531)
at com.intellij.codeInspection.ex.GlobalInspectionContextImpl.lambda$null$2(GlobalInspectionContextImpl.java:432)
at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1029)
at com.intellij.codeInspection.ex.GlobalInspectionContextImpl.lambda$runTools$3(GlobalInspectionContextImpl.java:428)
at com.intellij.concurrency.JobLauncherImpl$1MyTask.lambda$call$0(JobLauncherImpl.java:284)
at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:494)
at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:443)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:54)
at com.intellij.concurrency.JobLauncherImpl$1MyTask.call(JobLauncherImpl.java:271)
at com.intellij.concurrency.JobLauncherImpl$1MyTask.call(JobLauncherImpl.java:261)
at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1424)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)

I'm using IntelliJ IDEA 2016.3.5 (Build #IC-163.13906.18) and as SDK I am using Android Studio AI-162.3764568.

idea.jar from Android Studio doesn't contains isJUnit5TestClass method (but it exists in idea.jar from Intellij IDEA).

Android Studio SDK classpath contains following jars:

  • Android Studio lib/*
  • JDK lib/*
  • Intellij IDEA plugins/gradle/lib/* (because otherwise it throws NoSuchClass Gradle* exception)
  • Intellij IDEA plugins/junit/lib/* (by the same reason)
  • Intellij IDEA plugins/Groovy/lib/* (by the same reason)

I tried to remove Android Studio idea.jar from classpath and replace it with Intelij IDEA idea.jar but this didn't solve the problem.

1

Please sign in to leave a comment.