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

Capture logs during testing and print them in case of failure #587

Merged
merged 6 commits into from
Jan 29, 2025

Conversation

jnatten
Copy link
Contributor

@jnatten jnatten commented Jan 29, 2025

Dette er en ting jeg har tenkt på før, men fikk litt ny giv når @katrinewi støtte på en migreringsfeil som ikke var så lett å tolke ut av testene i dag.

Sånn det er før denne PR'en:

  • En test starter en myndla-api instans
  • Migering feiler stille
  • Testen feiler med en intetsigende database feilmelding

Sånn det er i denne PR'en:

  • En test starter en myndla-api instans
  • Migering feiler
  • Testen feiler med en intetsigende database feilmelding
  • Siden testen feilet så vil alle loggene som skjedde (i beforeAll + testen) bli printet til konsollen.

Det ser sånn ca sånn her ut:

image

This patch introduces a new feature of the `UnitTestSuite`:

  When tests are ran we collect logs for the `no.ndla` package in a
  buffer, and when a test fails the collected logs are printed for that
  test in particular.

  This allows us to keep clean and readable logs when tests are green,
  but will allow us to more easily find mistakes when a test fails.
Previously we just let the default scala runner handle printing
exceptions during startup. This works fine for most cases, but when we
want to capture logs in a test this does not get logged and captured.
This resulted in captured logs not appearing correctly
This resulted in captured logs not appearing correctly
@jnatten jnatten requested a review from a team January 29, 2025 11:46
Copy link
Member

@gunnarvelle gunnarvelle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool

While this is still not perfect (We will still log exceptions two times on
exit), the code itself is cleaner.
@jnatten jnatten merged commit 828e84c into master Jan 29, 2025
39 checks passed
@jnatten jnatten deleted the failing-test-logging branch January 29, 2025 13:40
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

Successfully merging this pull request may close these issues.

2 participants