TUnit icon indicating copy to clipboard operation
TUnit copied to clipboard

[Before(Test)] hooks don't report useful errors in VS (Code) or Rider

Open JohnGalt1717 opened this issue 4 months ago • 7 comments

Is there a way to get more than this:

BeforeTest hook failed
at TUnit.Engine.Services.HookExecutor.ExecuteBeforeTestHooksAsync(AbstractExecutableTest test, CancellationToken cancellationToken)
at TUnit.Engine.TestExecutor.ExecuteAsync(AbstractExecutableTest executableTest, CancellationToken cancellationToken)
at TUnit.Engine.TestExecutor.ExecuteAsync(AbstractExecutableTest executableTest, CancellationToken cancellationToken)
at TUnit.Engine.TestExecutor.ExecuteAsync(AbstractExecutableTest executableTest, CancellationToken cancellationToken)
at TUnit.Engine.Services.TestExecution.TestCoordinator.<>c__DisplayClass10_0.<<ExecuteTestInternalAsync>b__0>d.MoveNext()
at TUnit.Engine.Services.TestExecution.TestCoordinator.<>c__DisplayClass10_0.<<ExecuteTestInternalAsync>b__0>d.MoveNext()
at TUnit.Engine.Services.TestExecution.RetryHelper.ExecuteWithRetry(TestContext testContext, Func`1 action)
at TUnit.Engine.Services.TestExecution.RetryHelper.ExecuteWithRetry(TestContext testContext, Func`1 action)
at TUnit.Engine.Services.TestExecution.TestCoordinator.ExecuteTestInternalAsync(AbstractExecutableTest test, CancellationToken cancellationToken)

Obviously just calling the method at the start of every test works in this case but [Before(class)] has the same issue and that's less straight forward.

It would be nice if the errors actually directly reported like they do in the tests themselves.

JohnGalt1717 avatar Oct 14 '25 14:10 JohnGalt1717

Pretty sure this is an IDE issue, as if you run via the command line you should see the inner exception

thomhurst avatar Oct 14 '25 14:10 thomhurst

I ran this:

dotnet test Tests/Banking/BankingProviderTests/BankingProviderTests.csproj -- --treenode-filter "/*/BankingProviderTests/Transfers/TransfersTests/InternalToInternal_Succeeds"

This runs a single test.

This is what it gets:

   Tests\Banking\BankingProviderTests\bin\Debug\net10.0\BankingProviderTests.dll : error run failed: Tests failed: Tests\Banking\BankingProviderTests\bin\Debug\net10.0\TestResults\BankingProviderTests_net10.0_x64.log' [net10.0|x64]

Test summary: total: 0, failed: 0, succeeded: 0, skipped: 0, duration: 0.3s

Which is even worse than what the IDE is reporting.

JohnGalt1717 avatar Oct 14 '25 14:10 JohnGalt1717

Your filter is wrong. It should only have 4 segments - You've got 5.

dotnet test Tests/Banking/BankingProviderTests/BankingProviderTests.csproj -- --treenode-filter "/*/*/TransfersTests/InternalToInternal_Succeeds"

thomhurst avatar Oct 14 '25 14:10 thomhurst

OK, thanks. But why are all of the clients that consume this reporting junk instead of the proper error?

JohnGalt1717 avatar Oct 14 '25 15:10 JohnGalt1717

No idea!

thomhurst avatar Oct 14 '25 15:10 thomhurst

It's odd to me that it works fine if I just call the function directly in the test, but doesn't work with the hook. Is there any way to work around whatever the limitation is?

JohnGalt1717 avatar Oct 14 '25 17:10 JohnGalt1717

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Nov 28 '25 00:11 github-actions[bot]

This is still an issue with .NET 10 and Visual Studio 2026.

For reference, NUnit's [SetUp] feature correctly shows exceptions in the VS test output:

Image

robertcoltheart avatar Dec 02 '25 21:12 robertcoltheart