Mock frameworks for IDEA development.

Hi guys,

While studying intellij-community code I noticed you don't use any publicly available mock framework for internal testing. Is that right?
The reason I'm asking is that suppose I want to write some unit tests for code in the hg4idea module. I need mocks in my tests, but writing them by hand is a bit overkill. Can I add a test-scope dependency on, say, mockito for this particular module and place library under the lib folder?

Thanks.

6 comments

Please see http://confluence.jetbrains.com/display/IDEADEV/Testing+IntelliJ+IDEA+Plugins for more information regarding our test "philosophy".
What exactly do you want to mock in your tests?

0

Thanks for the link. It was very interesting to read.

The biggest benefit of this test approach is that tests are very stable and require very little maintenance once they have been written, no matter how much the underlying implementation is refactored or rewritten.

One sentence sums it all up. Functional tests are good, no doubt. They test on a big scale. The bigger the scale the less you are interested in details.
What I'm talking about is a unit-testing. And by unit I mean class/method. I need to mock a tiny little component like com.intellij.execution.process.ProcessListener to verify my object talks to its collaborator in a proper way. In other words I need mocks for verification of behavior. Just as usual in a mockland :-)

0

I see, I don't think there would be any problems using mock libraries in your tests.

0

If I was reviewing your pull request, I don't think I would accept it. Mock-based unit tests have very significant long-term maintenance costs, and in this case the costs will be borne not by you as a contributor but by the team at JetBrains who will need to fix the tests when they fail because of some internal refactoring (which will not break the code but will break the assumptions of your mocks).

0

yole wrote:


...which will not break the code but will break the assumptions of your mocks...


Good point. But I believe it doesn't have anything to do with the fact that tests are mock-based, but rather the test themselves.
Anyway I see what you mean.

Thanks.

0

Hi,

I've recently been looking into making my plugin code decoupled from the IntelliJ API where possible. Perhaps this is something you could look into pursing also?

It is of course a best practice to decouple your code in the first place, but it should make testing core logic a lot easier without attempting to mock large sections of the IntelliJ API.

Alan

0

Please sign in to leave a comment.