Search code examples
c#unit-testingmstestbeyondcompareapproval-tests

ApprovalTests DiffReporter is not popping up diff window unless the diff tool is open


I've been having an issue with ApprovalTests recently where the diff tool (BeyondCompare 3, in my case; I have a co-worker with the same issue using WinMerge) is flashing open and then closes immediately. The only way for the tool to stay open is by having the the tool open prior to running the tests.

I am using ApprovalTests 3.6; I know this issue existed in the previous version as well.

The method calling Verify is quite simple:

    [UseReporter(typeof(DiffReporter))]
    protected void VerifyTables(IEnumerable<DataTable> tables, bool showSchema = false)
    {
        Approvals.VerifyAll(tables.Select(t => GetXmlForApproval(t, showSchema).ToString()), "");
    }

As far as BeyondCompare is concerned - I've had this issue with TFS comparisons in Visual Studio, and it was due to TFS being set up to call BCompare.exe instead of BComp.exe. So, I tried making a custom implementation of the BeyondCompareReporter which calls BComp.exe instead of BCompare.exe, but using that didn't make a difference in this case.


Solution

  • The issue here is the some runners of unit tests will forcefully close (terminate) all processes launched by the unit test after it has finished. The reason BeyondCompare is working if previously opened is that processes wasn't launched via the unit test.

    I have seen this happen in 2 main ways
    1) Tests run via some versions of Resharper test runner.
    The way to solve this seems to be to just move to the latest version of resharper. Alternatively you can run the test via VisualStudio test runner

    2) Test run via some version of a test setting file .runsettings for MsTest
    The work around here seems to be to just delete the test setting file, although I believe the actual line is

    KeepExecutorAliveAfterLegacyRun
    

    More at: http://msdn.microsoft.com/en-us/library/jj635153.aspx