-
-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create custom xUnit test runner/discoverer #4
Comments
An additional benefit of a custom test runner is that custom [Fact] tests can have params, e.g. for receiving the rendered HTML and snippets. That might make tests more clean (no lookup needed it RenderResults). |
Looks like this is the sample to use: https://github.com/xunit/samples.xunit/tree/master/ObservationExample |
Asked Brad Wilson from xUnit about this, and his input is captured below. In summary, it looks as if the "Observation" sample linked above is the right starting place. The sad bit of news was that we would also have to implement the default xUnit functionality. Hopefully our xunit test framework can just delegate to the builtin one, so copy-pasting the source code from xUnit isnt necessary. |
@egil, this library blows my mind, kudo's! |
Hey Benjamin Thanks for the kind words. I figured out a solution, which admittedly is a little hacky, but it works. See https://github.com/egil/bunit/tree/xunit-runner/src/bunit.xunit/Xunit.Sdk if you are interested in the details. Waiting with the merge until I (hopefully) get a little feedback from the xUnit folks. Here is a screenshot of the code in action. https://twitter.com/egilhansen/status/1254147453076602883 |
Awesome, look very promising! If you'd like we're going to use the library in the Ant Design For Blazor project. If you want us to try nightlies etc. we'd be up to give some constructive feedback and PR's. You can contact me directly via email, [email protected]. |
I always welcome feedback. Unfortunately I have not set up a pack/push of nighties to nuget/myget, but I'll get to that when beta-7 is done. |
There are to problems with using the default runners/discoverers:
Currently are all
<Fact/>
tests inside the same .razor file, which runs the default expected output html test, listed as one test in the test runner. A custom test discovere for xUnit seems like the right approach to get the correct Facts reported to the test runner. It should also use theDisplayName
attribute when finding tests.If multiple xUnit tests exists in the same .razor file (declared via [Fact] attributes), the entire .razor component is re-rendered each time a test is executed, and a new renderer is instantiated each time. With a custom test runner we should be able to reuse the same renderer and then cache the output from the initial render. An alternative is to figure out how to only render some parts of a .razor file at the time.
There are some samples in the xunit repo that shows how to create both a custom discoverer and test runner: https://github.com/xunit/samples.xunit
The text was updated successfully, but these errors were encountered: