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

CurrentCulture affects rendered markup #1155

Closed egil closed 6 months ago

egil commented 1 year ago

Should bUnit default to always generate markup using a specific culture? When e.g. a decimal is converted to a string, whatever the Thread.CurrentThread.CurrentCulture and Thread.CurrentThread.CurrentUICulture will affect how the number is represented (e.g. thousand separators, decimal separator).

I think the answer is NO, bUnit should not dictate a culture by default, since I believe the Blazor runtime doesn't either when it generates markup in the browser. However, we could provide a convenient way for users to specify a culture. This is especially useful if a dev team is split across different cultures, where tests may pass in one culture but not in another.

At the very least, we should probably add an article in the docs that tell users how to control the culture. E.g. for xUnit, the typical solution is to include the UseCultureAttribute and that to tests, e.g.:

[UseCulture("en-US")]
[Fact]
public void My_component_test()
{
  // ...
}
linkdotnet commented 7 months ago

Seeing that the issue never really popped up for a user, I am much in favor of just closing the issue.

I don't see the obligation of highlighting this in our docs, as this is very bound to the test runner (xUnit, NUnit, MSTest, ...). Often times a simple Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); is good enough (and is independent of the runner).