question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Integration Tests which make use of `ControlTestBase` can erroneously pass when an exception is present

See original GitHub issue

Add the following test to System.Windows.Forms.UI.IntegrationTests. It should fail as an exception is thrown. But it passes.

[WinFormsFact]
public async Task Special_Test()
{
    using Form form = new();
    form.Shown += (object? sender, EventArgs e) => { throw new Exception("test"); };
    await RunFormWithoutControlAsync(() => form, async (form) =>
    {
        await MoveMouseAsync(form, new Point(0, 0), false);
        form.Close();
    });
}

Issue Analytics

  • State:open
  • Created 9 months ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
elachlancommented, Jan 5, 2023

Thank you, your input is greatly appreciated. I’ll discuss it a bit more here with the team. I think we can use the Application.SetUnhandledExceptionMode(https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.application.setunhandledexceptionmode?view=windowsdesktop-7.0) at the moment it is showing the unhandled exception message box. Whereas in a test it should fail, unless we are testing the unhandled exception message box.

1reaction
AArnottcommented, Jan 5, 2023

It sounds like WinForms deliberately swallows these exceptions. In general, a test can only fail if the exception can be detected, and a swallowed exception isn’t something that should fail a test because swallowing exceptions is intentional in some code and shouldn’t force test failures. Uncaught exceptions always crash a process, no matter what thread they are on. Test runners generally catch exceptions that escape the test method and report it as a test failure to avoid a process crash. GUI frameworks sometimes have no catch around event handlers, so an exception thrown from an event handler may crash the process. async void methods that throw almost always crash the process.

Now, WinForms’ ThreadException handler isn’t one I’m familiar with. If that would provide a way to ‘catch’ exceptions that would otherwise be swallowed, that could potentially be used as a hook to cause a test failure, although we’d need to know which test to associate the exception with. It would presumably preclude running tests in parallel too, but WinFormsFact may already have forced all tests to run sequentially, I don’t recall. Apparently throwing from these handlers doesn’t break the winforms app itself, so should it fail a unit test?

All this is to say… I don’t know what we should or can do in xunit.stafact to help catch these failures. If you understand the nuances of this exception handler more, maybe we should continue the discussion in the xunit.stafact repo.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - Testing conditions and exceptions in Integration Tests?
I have written several Unit Tests and now switched to write Integration Test in our Java (Spring Boot) app. We use JUnit and...
Read more >
14. Integration Testing
When the TestContext framework loads your application context, it can optionally configure instances of your test classes via Dependency Injection.
Read more >
Integration tests in ASP.NET Core
Integration tests evaluate an app's components on a broader level than unit tests. Unit tests are used to test isolated software components, ...
Read more >
What is Integration Testing (I&T)?
Learn strategies for integration testing, a type of software testing in which various modules in an application are tested as a combined unit....
Read more >
Integration Testing: Definitions, Types, and Best Practices - Brian
Integration testing allows them to recognize those missing exception scenarios and make revisions. External hardware interfaces: Bugs may arise ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found