resharper-pluginsresharper-sdk

Arbitrary checks in ReSharper plugin testing


As I learned from DevGuide testing ReSharper plugins works as follows:

  1. Plugin is loaded and test input file is passed to it
  2. Plugin performs it's actions on the passed file
  3. 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)
  4. 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:

  1. 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.


Solution

  • 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 QuickFixAvailabilityTestBase or QuickFixTestBase, which add the functionality for testing quick fixes. These are the classes that will do something and write the output to a .tmp file that is then compared to the .gold file.

    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, or BaseTestWithTextControl which 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 .tmp file to compare against the .gold.

    You should override the DoTest method. This will give you an IProject that is already set up, and you can do whatever you need to in order to test your extension's functionality. You can use project.Solution.GetComponent<> to get at any shell or solution component, and use the ExecuteWithGold method to execute something, write to the .tmp file and have ReSharper compare to the .gold file for you.