How to obtain IType/ITypeElement for Testing?

I want to write some helper methods that extract certain information from ITypes/ITypeElements. To write tests for these helpers I would like to obtain IType/ITypeElement instances for a test target class I already created. I just don't seem to be able to figure out how to do that... can anybody help me out here?

Thanks,
Best,
Sven

5 comments

You need to create a plugin test project, using the project templates installed by the SDK. Then you can create functional (not unit) tests. The test framework will create an in-memory ReSharper environment and solution and add files that exist on the file system, as specified by your test. There are base classes in the test framework to help test highlights, quick fixes, etc. These will call your plugin in the context of the file, and all PSI elements will be valid. Alternatively, you can get the file and walk the PSI tree yourself in your tests.

You can see more here: http://confluence.jetbrains.com/display/NETCOM/2.10+Testing+%28R8%29

0

This paragraph you just wrote should be added to the documentation page you referenced. Would make things much clearer... plus a documentation of the base classes would be really helpful. Just a list of the available types would be a great start. A sentence describing each one's pupose would actually make this framework learnable : /

Thanks anyways, I'm starting to get an idea of how things are meant to work.

0

Agreed. I am trying to update the docs, in between everything else. One thing you can do to get a list of useful base classes is to find the derived classes of BaseTest, BaseTestWithSolution and BaseTestWithSingleProject.

0

Thanks a lot. This is a good pointer!

0

I blogged about my experiences in writing R# tests: http://sven-amann.de/blog/2013/11/testing-resharper-plugins/. Hope it helps someone ;)

0

Please sign in to leave a comment.