Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Feb 8, 2026

Testing console methods that throw exceptions currently requires wrapping ConsoleAssert.Expect in try/catch blocks and manually tracking flags. This adds ExpectThrows and ExpectThrowsAsync to streamline exception assertions.

Changes

  • New Methods

    • ExpectThrows<TException> - validates console output and captures expected exception
    • ExpectThrowsAsync<TException> - async variant
    • Both return the caught exception for additional assertions
    • Support NormalizeOptions parameter consistent with existing Expect methods
  • Tests

    • Exception capture (sync/async)
    • Assertion failure when no exception thrown
    • Assertion failure when wrong exception type thrown
    • Normalization options support

Example

Before:

bool flag = false;
try
{
    ConsoleAssert.Expect(view, () => { ExceptionHandling.Main(); });
}
catch (FormatException)
{
    flag = true;
}
Assert.IsTrue(flag);

After:

var exception = ConsoleAssert.ExpectThrows<FormatException>(view, 
    () => { ExceptionHandling.Main(); });
Original prompt

This section details on the original issue you should resolve

<issue_title>Implement ExpectThrows</issue_title>
<issue_description>Currently to do assertions on throwing methods requires doing a try/catch. It would be nice to mimic other assertion libraries that have a method for asserting on an exception being thrown.

try
{
    IntelliTect.TestTools.Console.ConsoleAssert.Expect(view,
    () =>
    {
        ExceptionHandling.Main();
    });
}
catch (FormatException)
{
    flag = true;
}

Assert.IsTrue(flag);

Would be better written similar to:

IntelliTect.TestTools.Console.ConsoleAssert.ExpectThrows<FormatException>(view,
() =>
{
    ExceptionHandling.Main();
});
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 5 commits February 8, 2026 07:23
Co-authored-by: BenjaminMichaelis <22186029+BenjaminMichaelis@users.noreply.github.com>
…ve tests

Co-authored-by: BenjaminMichaelis <22186029+BenjaminMichaelis@users.noreply.github.com>
Co-authored-by: BenjaminMichaelis <22186029+BenjaminMichaelis@users.noreply.github.com>
Co-authored-by: BenjaminMichaelis <22186029+BenjaminMichaelis@users.noreply.github.com>
Copilot AI changed the title [WIP] Add ExpectThrows method for exception assertions Add ExpectThrows methods for exception assertion in console tests Feb 8, 2026
@BenjaminMichaelis BenjaminMichaelis marked this pull request as ready for review February 8, 2026 07:30
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.

Implement ExpectThrows

2 participants