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:
.gold
files are
completely different, or empty etc.); .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.
I did it! These steps resolve the problem:
ContextActionTestBase
to CSharpContextActionExecuteTestBase
;ExtraPath
property value as equal to RelativeTestDataPath
value (this value is the folder name where input and gold-file are located).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");
}
}