bUnit-dev / bUnit

bUnit is a testing library for Blazor components that make tests look, feel, and runs like regular unit tests. bUnit makes it easy to render and control a component under test’s life-cycle, pass parameter and inject services into it, trigger event handlers, and verify the rendered markup from the component using a built-in semantic HTML comparer.
https://bunit.dev
MIT License
1.14k stars 105 forks source link

StackOverflow Exception when running tests with vstest.console.exe #1227

Closed BenSchoen closed 1 year ago

BenSchoen commented 1 year ago

I have some tests using buint. The tests running in Visualstudio 2022. When running these tests with donet test or vstest.console.exe i got the exception below. I removed some test to check if a dedicated test is responsible for the error, but i had no success.

If i go back to version of bunit 1.18.4 i do not have the issue.

The active test run was aborted. Reason: Test host process crashed : Stack overflow. at System.Text.StringBuilder.Append(Char ByRef, Int32) at System.Text.StringBuilder.Append(System.String) at Bunit.Htmlizer.RenderAttributes(HtmlRenderingContext, System.ReadOnlySpan1<Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame>, Int32, Int32, System.String ByRef) at Bunit.Htmlizer.RenderElement(HtmlRenderingContext, System.ReadOnlySpan1, Int32) at Bunit.Htmlizer.RenderCore(HtmlRenderingContext, System.ReadOnlySpan1<Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame>, Int32) at Bunit.Htmlizer.RenderFrames(HtmlRenderingContext, System.ReadOnlySpan1, Int32, Int32) at Bunit.Htmlizer.RenderChildren(HtmlRenderingContext, System.ReadOnlySpan1<Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame>, Int32, Int32) at Bunit.Htmlizer.RenderElement(HtmlRenderingContext, System.ReadOnlySpan1, Int32) at Bunit.Htmlizer.RenderCore(HtmlRenderingContext, System.ReadOnlySpan1<Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame>, Int32) at Bunit.Htmlizer.RenderFrames(HtmlRenderingContext, System.ReadOnlySpan1, Int32, Int32) at Bunit.Htmlizer.RenderChildren(HtmlRenderingContext, System.ReadOnlySpan1<Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame>, Int32, Int32) at Bunit.Htmlizer.RenderElement(HtmlRenderingContext, System.ReadOnlySpan1, Int32) at Bunit.Htmlizer.RenderCore(HtmlRenderingContext, System.ReadOnlySpan1<Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame>, Int32) at Bunit.Htmlizer.RenderFrames(HtmlRenderingContext, System.ReadOnlySpan1, Int32, Int32) at Bunit.Htmlizer.RenderChildComponent(HtmlRenderingContext, System.ReadOnlySpan1<Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame>, Int32) at Bunit.Htmlizer.RenderCore(HtmlRenderingContext, System.ReadOnlySpan1, Int32) at Bunit.Htmlizer.RenderFrames(HtmlRenderingContext, System.ReadOnlySpan1<Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame>, Int32, Int32) at Bunit.Htmlizer.RenderCore(HtmlRenderingContext, System.ReadOnlySpan1, Int32) at Bunit.Htmlizer.RenderFrames(HtmlRenderingContext, System.ReadOnlySpan1<Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame>, Int32, Int32) at Bunit.Htmlizer.RenderChildComponent(HtmlRenderingContext, System.ReadOnlySpan1, Int32) at Bunit.Htmlizer.RenderCore(HtmlRenderingContext, System.ReadOnlySpan1<Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame>, Int32) at Bunit.Htmlizer.RenderFrames(HtmlRenderingContext, System.ReadOnlySpan1, Int32, Int32) at Bunit.Htmlizer.RenderChildComponent(HtmlRenderingContext, System.ReadOnlySpan1<Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame>, Int32) at Bunit.Htmlizer.RenderCore(HtmlRenderingContext, System.ReadOnlySpan1, Int32) at Bunit.Htmlizer.RenderFrames(HtmlRenderingContext, System.ReadOnlySpan1<Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame>, Int32, Int32) at Bunit.Htmlizer.RenderCore(HtmlRenderingContext, System.ReadOnlySpan1, Int32) at Bunit.Htmlizer.RenderFrames(HtmlRenderingContext, System.ReadOnlySpan1<Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame>, Int32, Int32) at Bunit.Htmlizer.RenderCore(HtmlRenderingContext, System.ReadOnlySpan1, Int32) at Bunit.Htmlizer.RenderFrames(HtmlRenderingContext, System.ReadOnlySpan1<Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame>, Int32, Int32) at Bunit.Htmlizer.RenderChildComponent(HtmlRenderingContext, System.ReadOnlySpan1, Int32) at Bunit.Htmlizer.RenderCore(HtmlRenderingContext, System.ReadOnlySpan1<Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame>, Int32) at Bunit.Htmlizer.RenderFrames(HtmlRenderingContext, System.ReadOnlySpan1, Int32, Int32) at Bunit.Htmlizer.RenderChildComponent(HtmlRenderingContext, System.ReadOnlySpan1<Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame>, Int32) at Bunit.Htmlizer.RenderCore(HtmlRenderingContext, System.ReadOnlySpan1, Int32) at Bunit.Htmlizer.RenderFrames(HtmlRenderingContext, System.ReadOnlySpan1<Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame>, Int32, Int32) at Bunit.Htmlizer.RenderCore(HtmlRenderingContext, System.ReadOnlySpan1, Int32) at Bunit.Htmlizer.RenderFrames(HtmlRenderingContext, System.ReadOnlySpan1<Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame>, Int32, Int32) at Bunit.Htmlizer.RenderChildren(HtmlRenderingContext, System.ReadOnlySpan1, Int32, Int32) at Bunit.Htmlizer.RenderElement(HtmlRenderingContext, System.ReadOnlySpan1<Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame>, Int32) at Bunit.Htmlizer.RenderCore(HtmlRenderingContext, System.ReadOnlySpan1, Int32) at Bunit.Htmlizer.RenderFrames(HtmlRenderingContext, System.ReadOnlySpan1<Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame>, Int32, Int32) at Bunit.Htmlizer.RenderCore(HtmlRenderingContext, System.ReadOnlySpan1, Int32) at Bunit.Htmlizer.RenderFrames(HtmlRenderingContext, System.ReadOnlySpan1<Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame>, Int32, Int32) at Bunit.Htmlizer.RenderChildComponent(HtmlRenderingContext, System.ReadOnlySpan1, Int32) at Bunit.Htmlizer.RenderCore(HtmlRenderingContext, System.ReadOnlySpan1<Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame>, Int32) at Bunit.Htmlizer.RenderFrames(HtmlRenderingContext, System.ReadOnlySpan1, Int32, Int32) at Bunit.Htmlizer.RenderChildren(HtmlRenderingContext, System.ReadOnlySpan1<Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame>, Int32, Int32) at Bunit.Htmlizer.RenderElement(HtmlRenderingContext, System.ReadOnlySpan1, Int32) at Bunit.Htmlizer.RenderCore(HtmlRenderingContext, System.ReadOnlySpan1<Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame>, Int32) at Bunit.Htmlizer.RenderFrames(HtmlRenderingContext, System.ReadOnlySpan1, Int32, Int32) at Bunit.Htmlizer.RenderChildComponent(HtmlRenderingContext, System.ReadOnlySpan1<Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame>, Int32) at Bunit.Htmlizer.RenderCore(HtmlRenderingContext, System.ReadOnlySpan1, Int32) at Bunit.Htmlizer.RenderFrames(HtmlRenderingContext, System.ReadOnlySpan1<Microsoft.AspNetCore.Components.RenderTree.RenderTreeFrame>, Int32, Int32) at Bunit.Htmlizer.RenderChildComponent(HtmlRenderingContext, System.ReadOnlySpan1, Int32) at Bunit.Htmlizer.RenderCore(HtmlRenderingContext, System.ReadOnlySpan`1, Int32) at Bunit.Htmlizer.RenderFrames(HtmlRenderingCon

linkdotnet commented 1 year ago

Hey, thanks for reporting.

by any chance do you have any code (at best minimal and reproducible) that you could show?

often times such issues arise when you call something like Click inside WaitForHelpers.

egil commented 1 year ago

Hmm glancing at the stack trace, the endless loop seems to happen while generating rendered markup. As far as I know it should not be possible to have a self referring render tree.

I would really like to see the component-under-test and test case.

BenSchoen commented 1 year ago

Hey all

Tanks for the immediate response and hints. I tried to isolate the problem but without success. It seems that there is something which influences other tests....

I will try it soon and let you know when i found something.

BenSchoen commented 1 year ago

Hello

I am not able to extract the problem to a separate project. I have some findings:

I build an example, that you can see how the setup and the test case is. I am sorry, i am not allowed to share the code here.... BunitTestProject.zip]

egil commented 1 year ago

Hi @BenSchoen,

I just downloaded your sample and ran it in Visual Studio without issues. Also ran fine from dotnet test. Did you include the failing test?

BenSchoen commented 1 year ago

No it is sadly not possible to let the test fail with the small project.... But the way i set up the test and the component is the same.

egil commented 1 year ago

Can you share the full project with us (privately, through email, if needed)?

egil commented 1 year ago

I think we have found the culprit. If things go as planned, we will have a preview release soon that you can test out.

egil commented 1 year ago

There should be a new 1.24.x-preview release out now. Please give it a go (remember to update both your projects that reference bunit).

BenSchoen commented 1 year ago

@egil Yes i can confirm that the problem is solved with the 1.24.x-preview