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?

0
2 comments

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.

0

Many functions are using editor and docs as a parameter. I just gave a simple example. Most functions are more complicated

0

Please sign in to leave a comment.