Skip to content

Logs from request/controller tests. #1179

Answered by kaplanelad
felipesere asked this question in Q&A
Discussion options

You must be logged in to vote

Hey,
tracing is a global dispatcher, so you can’t initialize it more than once, this is the reason why the logging is not shown by default

Here are two options to debug the test:

  1. Run the test in debug mode.
  2. You can initialize the logger in a specific test using logger::init. Here's an example:
    #[tokio::test]
    #[serial]
    async fn can_get_home() {
        request::<App, _, _>(|request, ctx| async move {
            // Enable the logger
            let _ = logger::init::<App>(&ctx.config.logger);
            let res = request.get("/api").await;
    
            assert_eq!(res.status_code(), 200);
            res.assert_json(&serde_json::json!({"app_name":"loco"}));
        }).await;
    }

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@felipesere
Comment options

Answer selected by felipesere
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants