Test line extensions generated by EditorLinePainter
已计划
Is it possible to test line extensions generated using EditorLinePainter? I didnt find any information about it.
I didnt find any useful function for that in:
Thank you for your help
Tomas
请先登录再写评论。
Hi Tomas,
Sorry, it's not clear what are you trying to do, can you please specify? Are you working on custom plugin?
Hi,
i am sorry. I am developing plugin, where i paint additional text at the end of some lines (line extensions). For this, i am using EditorLinePainter.class and i am overriding getLineExtensions method to paint a text.
And i would like to write unittest for this functionality, to check if the text was painted at specified line.
I would expect testHighlighting() from CodeInsightTestFixture.class would run my plugin code and paint the text or something similar. But it doesnt work and i didnt find any function to do that.
How can i test EditorLinePainter?
Hello Tomas,
If possible please describe in more details what are you planning to test. Thank you
Hi Olga,
of course. So firsly i will describe functionality of my plugin. As i said i have a class which extend from:
https://github.com/JetBrains/intellij-community/blob/master/platform/platform-impl/src/com/intellij/openapi/editor/EditorLinePainter.java
In this class i override method getLineExtensions(). Inside the method, i create instances of the object:
https://github.com/JetBrains/intellij-community/blob/master/platform/platform-impl/src/com/intellij/openapi/editor/LineExtensionInfo.java
I return collection of these instances.
This way i am able to paint custom text at different lines to different files in editor. Example:
The red text (its not clickable and cannot be edited, its just painted there) is result. And i want to unit test this.
Tomas
Thank you for answer. So how could i retrieve those 'rendered graphical elements'/pictures in my unittest? So i can compare then with expected ones.
For example, I can suggest a tool which our QA Automation Team is using: https://mvnrepository.com/artifact/ru.yandex.qatools.ashot
If read about that tool here:
https://github.com/pazone/ashot
It looks like it can retrieve graphical elements from websites. But i need to retrieve graphical elements generated using getLineExtensions() function. Maybe i am missing something. Could you tell me more how could i use that tool to compare line extensions graphical elements?
That tool may be used apart from web. Please refer to the class: https://github.com/pazone/ashot/blob/master/src/main/java/ru/yandex/qatools/ashot/comparison/ImageDiffer.java
If i understand it correctly, i can use this class to compare two images. But the problem is, i dont know how to retrieve 'actual' image. By that, i mean, i dont know how to automatically retrieve line extention image in unittest of my plugin.
You can make a screenshot, and then compare it with the expected one using ImageDiffer#makeDiff.
For that, you may use tools from java.awt package: https://stackoverflow.com/questions/4490454/how-to-take-a-screenshot-in-java