Integration Tests which make use of `ControlTestBase` can erroneously pass when an exception is present
See original GitHub issueAdd 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:
- Created 9 months ago
- Comments:8 (8 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.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.