Search code examples
c#.netresharperresharper-9.0resharper-sdk

ReSharper SDK test for Context Action doesn't work


I try to test my custom ReSharper Context Action using ReSharper SDK built-in test infrastucture. I've created an input file, an output file (.gold) and run the test. Two problems occur:

  1. Test is always successful (even if input and .gold files are completely different, or empty etc.);
  2. There is no .tmp file appears along with input and .gold files.

However, if I rename input file, then the test run fails with "file does not exist" exception.

My test project's structure is the same as described in docs.

TestEnvironment.cs:

[assembly: RequiresSTA]

[ZoneDefinition]
public class TestEnvironmentZone : ITestsZone, IRequire<PsiFeatureTestZone>
{
}

[SetUpFixture]
public class ReSharperTestEnvironmentAssembly : ExtensionTestEnvironmentAssembly<TestEnvironmentZone>
{
}

Test class:

[TestFixture]
public class FooContextActionTests : ContextActionTestBase<FooContextAction>
{
    protected override void ProcessAction(Func<FooContextAction> action, ITextControl control, ISolution solution)
    {
    }

    protected override string ExtraPath { get; }

    protected override string RelativeTestDataPath => @"FooContextActionTests";

    [Test]
    public void Test01()
    {
        DoTestFiles("Test01.cs");
    }
}

I've made the similar test for simple quick-fix. That test works as expected and reacts to any change of input or .gold file. So the question is how to test Context Action properly.

ReSharper SDK 9.2 is used.


Solution

  • I did it! These steps resolve the problem:

    1. Update to ReSharper.SDK v10 (it is not mandatory, I guess);
    2. Change base test class from ContextActionTestBase to CSharpContextActionExecuteTestBase;
    3. Set the ExtraPath property value as equal to RelativeTestDataPath value (this value is the folder name where input and gold-file are located).
    4. Remove ProcessAction override.

    This test class works correctly:

    [TestFixture]
    public class FooContextActionTests  : CSharpContextActionExecuteTestBase<FooContextAction>
    {
        protected override string ExtraPath => "FooContextActionTests";
    
        protected override string RelativeTestDataPath => "FooContextActionTests";
    
        [Test]
        public void Test01()
        {
            DoTestFiles("Test01.cs");
        }
    }