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

Improving the examples - adding tests #3263

Open
szabgab opened this issue Mar 12, 2025 · 2 comments
Open

Improving the examples - adding tests #3263

szabgab opened this issue Mar 12, 2025 · 2 comments

Comments

@szabgab
Copy link

szabgab commented Mar 12, 2025

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

async fn main() {
   ...
   let app = Router::new()
   ...
}

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

fn app() -> Router {
}

and then write

async fn main() {
   ...
   let app: Router = app();
   ...
}

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.

szabgab added a commit to szabgab/axum that referenced this issue Mar 12, 2025
@jplatte
Copy link
Member

jplatte commented Mar 12, 2025

We have two testing examples. I think the noise and maintenance effort of adding tests to all examples would be bigger than the benefit.

@yanns
Copy link
Collaborator

yanns commented Mar 12, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants