Skip to content
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

Closed
egil opened this issue Aug 6, 2019 · 7 comments · Fixed by #103
Closed

Create custom xUnit test runner/discoverer #4

egil opened this issue Aug 6, 2019 · 7 comments · Fixed by #103
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@egil
Copy link
Member

egil commented Aug 6, 2019

There are to problems with using the default runners/discoverers:

  1. 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 the DisplayName attribute when finding tests.

  2. 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

@egil
Copy link
Member Author

egil commented Aug 6, 2019

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).

@egil
Copy link
Member Author

egil commented Aug 7, 2019

Looks like this is the sample to use: https://github.com/xunit/samples.xunit/tree/master/ObservationExample

@egil egil added enhancement New feature or request help wanted Extra attention is needed labels Sep 8, 2019
@egil
Copy link
Member Author

egil commented Jan 5, 2020

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.

2020-01-05 08_08_22-Slack _ general _ xUnit net

@egil egil added this to the beta-7 milestone Apr 3, 2020
@egil egil closed this as completed Apr 25, 2020
@vertonghenb
Copy link

@egil, this library blows my mind, kudo's!
However it's not clear to me if this issue is going to resolved (e.g show multiple tests in 1 .razor file). Do you mind elaborating on this?

@egil
Copy link
Member Author

egil commented Apr 26, 2020

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

@egil egil self-assigned this Apr 26, 2020
@vertonghenb
Copy link

vertonghenb commented Apr 26, 2020

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].
https://append-it.github.io/ant-design-blazor/

@egil
Copy link
Member Author

egil commented Apr 29, 2020

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].
https://append-it.github.io/ant-design-blazor/

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.

@egil egil linked a pull request Apr 30, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants