Skip to content

Migrate UnitTests that require keyboard/mouse input to UnitTests.Parallelizable #4365

@tig

Description

@tig

In

I proved that any unit test that needs to render, even if it uses Views, can now be authored in UnitTests.Parallelizable. See UnitTests.Parallizable/Drawing.

Now we need to move some tests that require keyboard / mouse input into Application.

It should now be possible to do this:

var app = new ApplicationImpl();
app.Init(nul, "fake");

// Do anything you used to be able to in a Unit Test that used Application

// e.g.
app.RaiseNewKeyDownEvent (...);
app.RaiseNewMouseEvent (...);

app.LayoutAndDraw();

DriverAssert.AssertDriverContentsAre (expected, _output);

app.Shutdown(); // technically not needed because there's no static state!

First step is to write a sample unit tests in the UnitTests.Parallelizable project. Try porting this one:

    [Fact]
    [AutoInitShutdown]
    public void CaptionedTextField_DoesNotOverspillViewport_Unicode ()
    {
        string caption = "Mise" + char.ConvertFromUtf32 (int.Parse ("0301", NumberStyles.HexNumber)) + "rables";

        Assert.Equal (11, caption.Length);
        Assert.Equal (10, caption.EnumerateRunes ().Sum (c => c.GetColumns ()));

        TextField tf = GetTextFieldsInView ();

        tf.Title = caption;
        Application.RaiseKeyDownEvent ('\t');
        Assert.False (tf.HasFocus);

        tf.Draw ();
        DriverAssert.AssertDriverContentsAre ("Misérables", output);
        Application.Top.Dispose ();
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    Status

    ✅ Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions