How to write unit test cases for a function that takes document or editor as argument?
Answered
I coded a plugin for intellij. I had a function that takes an editor as input and finds the current cursor and returns the text from that line to previous 5 lines. How to write unit test cases for something like this? Is there any reference online that you guys developed?
Please sign in to leave a comment.
Hi,
The common approach is to test features as a whole. Your description suggests that you want to test a single function. What is the point of this function's existence? If it is used in a functionality which has a visible effect, then test this effect. Function returning text from five lines before feature sounds like an implementation detail.
Many functions are using editor and docs as a parameter. I just gave a simple example. Most functions are more complicated