How to enable the Run JUNIT test context menu for the Gosu Language
The Gosu Language produces Java byte codes but has its own Psi Tree. I want to enable running JUnit tests from a Gosu class that has the proper annotations. However, the existing JUnit implementation classes check for PsiElements that are PsiClass, PsiMethod, etc. and as they are part of the platform, I cannot change them. For example, AbstractInClassConfigurationProducer has a method
setupConfigurationFromContext()
that checks
if (element instanceof PsiClass && isTestClass((PsiClass)element)) ...
which of course fails. Most of the classes assume they are dealing with a Psi Tree that is for Java. I want to replace tests like the above with something like this:
if (element instanceof GosuPsiClass && isTestClass((GosuPsiClass)element)) ...
What is a reasonable way to extend or configure IntelliJ so it recognizes my test classes, and so that I can actually run tests in my Gosu classes that are compiled to Java byte codes?
By the way, I am currently using IJ 2017 (most recent version).
Please sign in to leave a comment.
Hi,
I don't think there is a way to reuse JUnitConfiguration in any means as it is dedicated to `PsiClass` and `PsiMethod` from different verifications to building classpath, etc. So you would need to create your own configuration with your own providers, etc.
Sorry for the inconvenience.
Anna
I should mention that we have wrapper classes we can produce around GosuPsiClass objects to make them a subclass of PsiClass, and also for GosuPsiMethod/PsiMethod, GosuPsiPackage/PsiPackage, etc. Are there some plugins we could implement and register in plugin.xml so that the JUnitConfiguration would see our classes/methods as PsiClass and PsiMethod? I imagine we could supply a producer. There seem to be about 30 producers that are being used (see list below) for various languages.
Surely it is not the case that every JVM-based language reimplements the entire JUnit mechanism. We are in this situation because we originally made GosuPsiClass directly inherit from PsiClass, but we were told that this is not recommended by JetBrains because it makes our code dependent on what JetBrains does with the Java PsiTree and Java plugin classes in general.
Just to be clear, ultimately we produce Java .class files for Gosu, so the JUnit mechanism should work at runtime just fine. The only issue is getting the test classes and methods to be recognized from GosuPsiClass/GosuPsiMethod.
Which of these 32 producers would we have to provide to get JUnitConfiguration to work for Gosu?
The main producer for test class/test method is:
or better you implement your `com.intellij.execution.testframework.AbstractInClassConfigurationProducer`
I made some progress implementing the following classes:
AbstractGosuTestConfigurationProducer.java
GosuAbstractInClassConfigurationProducer.java
GosuPsiMemberParameterizedLocation.java
GosuRunConfigurationExtensionManager.java
GosuRunConfigurationModule.java
GosuTestInClassConfigurationProducer.java
and modifying plugin.xml to include the appropriate plugins. Now the context menu shows "Run Test ..." and when I choose that menu item, the tests start, but they get exceptions starting up. So I think I am on the right track.