flutter-intellij
flutter-intellij copied to clipboard
Feature request : Shortcut to create tests
Would be nice to have a shortcut to create test when we have one of those popup:
A bonus would be that if the class is a widget it create a template for widget test, if not unit test.
That a functionality we have already on Android:
It's very useful because it create a template test file directly in same place/package as the class.
For our case if we have a class in lib/catalog/bloc/mybloc.dart
it will create a test file in test/catalog/bloc/mybloc_test.dart
Hey @pq I'm trying to familiarize myself with the project by implementing this feature, can you tell me where I can find the code for this actions please ?

because I don't find how I can add my action here :/ thanks !
From what I've understand it's an IntentAction that I need, but I need to know if I'm in the a context of a class or not :/ finding the code that do those actions will help me a lot to do that
@jaumard: awesome that you're looking at this!
As a general rule if you're trying to figure out how something works in IDEA, it's best to grab the source and search around. (Their docs aren't great.) These instructions for setting up the Dart Plugin for development may be handy:
https://github.com/JetBrains/intellij-plugins/blob/master/Dart/README.md
I'll take a look myself and see if I find anything promising and report back...
OK. After some poking around I have a few ideas.
Once you have the source, I'd start by looking for contributors to the testCreator
extension point. Look at this for example:
<testCreator language="JAVA" implementationClass="com.intellij.testIntegration.JavaTestCreator"/>
I'm guessing you could model a FlutterTestCreator
after this?
I need to know if I'm in the a context of a class or not :/ finding the code that do those actions will help me a lot to do that
Once you've got a test creator stubbed out, I'd look in the Flutter IntelliJ sources for places that reference PsiElement
. (io.flutter.FlutterUtils#isFlutteryFile
may come in handy too.)
Have fun!
@pq thanks ! Yeah basically that's what I did, I retrieved Dart plugin and this plugin and was trying to dig into those ^^ but even like that I find it really difficult to do things lol (for example I still don't know how convert to statefulWidget work as I didn't find the code for that...) it take my one day just to be able to have Create Test
when I do alt+enter on the class name lool
Now I'll check the JavaTestCreator and try to make a FlutterTestCreator ^^
At least work in progress :)
Great progress!
One reason you may not have found anything close to what you want to do is that everything with deep Dart language model knowledge (e.g., code generation, fixes and refactoring) is implemented in the (Dart) analysis server. The more I think about this task, the more I think that the test code generation part should happen there. Could you give some details about the logic you want to implement?
FYI @scheglov @bwilkerson
Ho that might explain it ! :) but even the text of the action I wasn't able to find it lool because from there I would have been able to follow the white rabbit in the correct class to see its all in analysis server.
What I want to implement in short term is :
- to create an empty test (or widget test) file under the same package as the source (but in test directory).
- if test already exist, "create test" become "go to test" and it open the test file on click
In long term I want :
- a popup to choose which method I want to tests and generate a scaffold of those method tests.
- checkbox to generate or not setup teardown methods
OK. On second thought this might be more easily done on the client-side.
In the Dart plugin sources, com.jetbrains.lang.dart.ide.generation.BaseDartGenerateHandler
may be a good place to start looking. Also, maybe com.jetbrains.lang.dart.ide.actions.CreateDartFileAction
.
@alexander-doroshko might have ideas too (but may not chime in for a while since he's on vacation)
I would strongly urge us to support this via server so that we don't have to do the same work in multiple clients. I believe that this would align nicely with the LSP Code Lens Request, and we could add something similar to the server's protocol.
So bottom line :) better if I wait a bit right ? ^^
If it's something you'd really like to see happen, I'd suggest opening a bug in the SDK issue tracker (https://github.com/dart-lang/sdk/issues/new) and reference back to this issue so we can track it.
Thanks!
done @pq :) feel free to add more information if you can, as I don't know that much the analysis server and the way it works https://github.com/dart-lang/sdk/issues/35595
It's been 3 years. Please, add this feature already
/fyi @bwilkerson
This would be so great, please consider adding it