Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fluent assertions #3993

Draft
wants to merge 14 commits into
base: v2_develop
Choose a base branch
from
Draft

Fluent assertions #3993

wants to merge 14 commits into from

Conversation

tznind
Copy link
Collaborator

@tznind tznind commented Mar 16, 2025

Goals

Perform 'automation' style tests using black box input/output.

  • Design from ground up to prevent tests ever hanging (i.e. with timeouts etc baked in)
  • Simplify API so user doesn't need to know as much about the internals of Terminal.Gui to test things (e.g. no need to call NewKeyEvent etc)
  • Traceability (comprehensive logging and 'screenshoting' to assist debugging failure states)
  • v2 drivers only but ideally support net and win
  • Input events supplied at raw 'console' level i.e. going through whole application/driver subsystem.

Examples

Started exploring a way to empower our users and ourselves to write cleaner tests around full Terminal.Gui application loops.

    [Fact]
    public void TestWindowsResize ()
    {
        var lbl = new Label ()
                                {
                                    Width = Dim.Fill ()
                                };
        using var c = With.A<Window> (40, 10)
                          .Add (lbl )
                          .Assert (lbl.Frame.Width.Should().Be(38)) // Window has 2 border
                          .ResizeConsole (20,20)
                          .Assert (lbl.Frame.Width.Should ().Be (18))
                          .Stop ();

    }

Also

    [Fact]
    public void ContextMenu_Click ()
    {
        var clicked = false;

        var ctx = new ContextMenu ();
        var menuItems = new MenuBarItem (
                                         [
                                             new ("_New File", string.Empty, () => { clicked = true; })
                                         ]
                                        );

        using var c = With.A<Window> (40, 10)
                          .WithContextMenu(ctx,menuItems)
                          // Click in main area inside border
                          .RightClick(1,1)
                          .ScreenShot ("After open menu",_out)
                          .LeftClick (3, 3)
                          .Stop ();
        Assert.True (clicked);
    }

Produces


  Standard Output: 
After open menu:
┌──────────────────────────────────────┐
│                                      │
│┌───────────┐                         │
││ New File  │                         │
│└───────────┘                         │
│                                      │
│                                      │
│                                      │
│                                      │
└──────────────────────────────────────┘


Class Diagram

image

Fixes

  • Fixes #_____

Proposed Changes/Todos

  • Todo 1

Pull Request checklist:

  • I've named my PR in the form of "Fixes #issue. Terse description."
  • My code follows the style guidelines of Terminal.Gui - if you use Visual Studio, hit CTRL-K-D to automatically reformat your files before committing.
  • My code follows the Terminal.Gui library design guidelines
  • I ran dotnet test before commit
  • I have made corresponding changes to the API documentation (using /// style comments)
  • My changes generate no new warnings
  • I have checked my code and corrected any poor grammar or misspellings
  • I conducted basic QA to assure all features are working

@TheTonttu
Copy link
Contributor

FYI there are some license related controversy surrounding Fluent Assertions. 7.x was the last Apache licensed version before the library switched to custom hybrid license. It doesn't really affect this project but just something to keep in mind if you're planning on relying on it extensively.

@tznind
Copy link
Collaborator Author

tznind commented Mar 16, 2025

Interesting, in that case maybe I will just switch to Action and let caller decide. Thanks for the heads up!

@tznind
Copy link
Collaborator Author

tznind commented Mar 16, 2025

I've chopped out fluent assertions so we can stick with MIT license and renamed the new project FluentTesting instead to avoid any confusion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants