As I learned from DevGuide testing ReSharper plugins works as follows:
- Plugin is loaded and test input file is passed to it
- Plugin performs it's actions on the passed file
- ReSharper's test environment writes plugin actions results to .tmp file in a special format that depends on the type of functionality tested (for example, if we test completion, .tmp file will contain the list of generated completion items)
- ReSharper's test environment compares .tmp file with .gold file to decide if test is failed or succeeded
But I need the following scenario. The first two steps are the same as the above ones, then:
- I write code that obtains the results of plugin's actions and check are they what I'm expected so I can make test fail if needed
How can I achieve this?
I need it because I have a code that uses AST generated by ReSharper to build some graphs and I want to test are the graphs built correctly.
Yes, you can do this. You need to create your own test base class, instead of using one of the provided ones.
There is a hierarchy of base classes, each adding extra functionality. Usually, you'll derive from something like
QuickFixAvailabilityTestBaseorQuickFixTestBase, which add the functionality for testing quick fixes. These are the classes that will do something and write the output to a.tmpfile that is then compared to the.goldfile.These classes themselves derive from something like
BaseTestWithSingleProject, which provides the functionality to setup an in-memory solution and project that's populated with files you specify in your test, orBaseTestWithTextControlwhich also gives you a text control for the file you're testing. If you derive from this class directly (or with your own custom base class), you can perform the action you need for the actual test, and either assert something in memory, or write the appropriate text to the.tmpfile to compare against the.gold.You should override the
DoTestmethod. This will give you anIProjectthat is already set up, and you can do whatever you need to in order to test your extension's functionality. You can useproject.Solution.GetComponent<>to get at any shell or solution component, and use theExecuteWithGoldmethod to execute something, write to the.tmpfile and have ReSharper compare to the.goldfile for you.