question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Prevent unit tests from trying to acquire Application Default Credentials

See original GitHub issue

A number of unit tests trigger autoconfiguration of DefaultCredentialsProvider. The symptom of it is “java.io.IOException: The Application Default Credentials are not available” output, plus the test takes longer than it should (because interacting with file system is relatively expensive).

  1. In an environment that does not have ADC, run mvn test, which will run unit tests only, and inventory all tests that complain about credentials. Hint: you can cheat here and take any JUnit output from GitHubActions, as credentials are unavailable there.
  2. Pick a test from your list. Figure out what needs to be done in test setup to override credentials, so that autoconfigured DefaultCredentialsProvider is never instantiated. Hint: it’s going to be a matter of either making a @Bean of type CredentialsProvider available in test configuration, or in using .withBean() to do the same in programmatically generated context. There are examples of both in the codebase. Some instances use a mock(CredentialsProvider.class), while others return a new credentials provider as a lambda () -> NoCredentialsProvider.create().

Bonus: measure how long all unit tests take to run before you start making changes, and measure the same after all changes are done. How much faster have our unit tests gotten?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
elefeintcommented, Sep 19, 2022

@Mowee please open a new issue describing what you are trying to achieve. This issue was for an internal test infrastructure, which should not affect you unless you are working on Spring Cloud GCP project.

0reactions
Moweecommented, Sep 19, 2022

@elefeint Thank you, I will do.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How Application Default Credentials works | Authentication
This page describes the locations where Application Default Credentials (ADC) looks for credentials. Understanding how ADC works can help you understand ...
Read more >
Disable security for unit tests with spring boot - Stack Overflow
I can launch the application fine and the security is working fine. However, I have some components that I want to test without...
Read more >
Use Google Cloud user credentials when testing containers ...
To get your default user credentials on your local environment, you have to use the gcloud SDK. You have 2 commands to get...
Read more >
How to Disable or Skip Unit Test in Xcode
Never disable unit tests unless you are 100% sure and know why they are failing. Remember, unit tests are your friend! They watch...
Read more >
Best practices for writing unit tests - .NET - Microsoft Learn
This article describes some best practices regarding unit test ... You can avoid these dependencies in your application by following the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found