-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Improving the examples - adding tests #3263
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
Comments
We have two testing examples. I think the noise and maintenance effort of adding tests to all examples would be bigger than the benefit. |
For people who would like starting contributing, it can be a nice way to add tests for one example. Step by step, we could reach completion. |
Extract the Router creation. Return some content to the web client. Test the routes. See tokio-rs#3263
- Create function to defined the route to make it testable. - Return data from the POST request to make it testable. - Add test. See tokio-rs#3263
* Move the router definition to its own function. * Add test * See tokio-rs#3263
I think having additional indirection in examples complicates the learning process. I think most people want to learn incrementally and having an additional 50-100 lines of tests on examples equivalent to hello world doesn't really achieve that goal. I'd restrict testing to more advanced examples only. If the goal is to help users write tests for their routers, there are ready examples for that. Axum tries not to introduce implicit behaviour changes, meaning examples are unlikely to break once written. If there are breaking changes, they can be caught using |
Looking at the examples in the
examples
folder I see that many don't come with tests.Having tests with the examples will both help make sure that they stay correct as axum changes and it will help the would be developers to learn how to test.
As I see many of the examples have
This, as far as I understand, makes it impossible to use the router in the tests. So I think it would be a good idea to refactor these examples to defined a function
and then write
I'd be happy to do this work for some of the examples, but I'd like to know if you even consider this a good idea.
The text was updated successfully, but these errors were encountered: