Skip to content

QoL suggestion: fail fast in Assert.Multiple under debugger #4738

Closed

Description

@MaceWindu

While Assert.Multiple is nice for failure reporting on test runs, it is quite bad when you try to debug test compared to regular assert.

  • with simple assert you get exception on assertion failure and could debug it
  • with Assert.Multiple you get exception at the end where you probably lost all related test context already and need to put manual breakpoints inside of delegate to be able to debug first failure (or comment Assert.Multiple wrap)

I propose to throw assert exception on first failure if process is under debug (Debugger.IsAttached == true) with some kind of switch for backward compatibility. E.g. for those who use tests with debbugger for any reason or just enjoy having troubles during debugging.

Activity

  1. OsirisTerje commented on Jun 26, 2024

    @OsirisTerje
    Member

    Nice idea! Could be enabled using a setting. Would you like to do a PR for this ?

  2. MaceWindu commented on Jun 27, 2024

    @MaceWindu
    ContributorAuthor

    Sure #4739

    Need some help with:

    • what else is missing?
    • default value true or false? I assume it should be false for backward compat.
  3. OsirisTerje commented on Jul 2, 2024

    @OsirisTerje
    Member

    default value true or false? I assume it should be false for backward compat.

    Yes :-)

    Can't think of anything else missing right now.

  4. added this to the 4.2 milestone on Jul 3, 2024
  5. OsirisTerje commented on Jul 3, 2024

    @OsirisTerje
    Member

    Need to raise a separate documentation issue for this.

  6. RenderMichael commented on Jul 8, 2024

    @RenderMichael
    Contributor

    I am also interested in this.

    Thanks to first-change exceptions, the debugger stops whenever anything throws, even if it is caught (unless Just My Code is enabled).

    Therefore you could have something like

    if (DummyThrowForDebugger)
    {
        try
        {
            throw new Exception();
        }
        catch (Exception)
        {
        }
    }

    And the debugger will still break here.

    Alternatively, you could just call System.Diagnostics.Debugger.Break(); directly.

    This will enable debugger stopping without breaking Assert.Multiple functionality.

  7. OsirisTerje commented on Jul 8, 2024

    @OsirisTerje
    Member

    @RenderMichael But does the PR, which is now merged,solve this for you?

  8. RenderMichael commented on Jul 8, 2024

    @RenderMichael
    Contributor

    It solves it in the same way commenting out Assert.Multiple would. We’d lose the second, third, etc. error message, and in order to debug through those, the first assertion needs to be commented out or resolved.

  9. MaceWindu commented on Jul 9, 2024

    @MaceWindu
    ContributorAuthor

    Such behavior also could be useful. @OsirisTerje any objections to convert new boolean option to enumeration like that:

    enum MultipleAssertBehaviorUnderDebugger
    {
        Default,
        ThrowOnFirstFailure,
        ThrowOnEachFailure
    }
  10. MaceWindu commented on Jul 9, 2024

    @MaceWindu
    ContributorAuthor

    Actually I think we just need to follow @RenderMichael proposal and change behavior to throw first-chance exceptions. Having two throw modes doesn't add any value

  11. MaceWindu commented on Jul 9, 2024

    @MaceWindu
    ContributorAuthor

    Submited PR #4749

  12. MaceWindu commented on Jul 9, 2024

    @MaceWindu
    ContributorAuthor

    Also submitted adapter PR #1188

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions