Prevent unit tests from trying to acquire Application Default Credentials
See original GitHub issueA 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).
- 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. - 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 typeCredentialsProvider
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 amock(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:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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.
@elefeint Thank you, I will do.