About 254,000 results
Open links in new tab
  1. spring - What is the replacement for the deprecated @MockBeans …

    Dec 2, 2024 · Indeed, starting with Spring Boot v3.4.0, the Mock Bean annotation (@MockBean) is marked as deprecated. I wrote an integration test that used this annotation (@MockBean).

  2. Populating Spring @Value during Unit Test - Stack Overflow

    Jun 28, 2013 · If possible I would try to write those test without Spring Context. If you create this class in your test without spring, then you have full control over its fields. To set the @value …

  3. Junit 5 with Spring Boot: When to use @ExtendWith Spring or …

    Apr 26, 2020 · When the test requires a Spring Test Context ( to autowire a bean / use of @MockBean ) along with JUnit 5's Jupiter programming model use …

  4. How to set environment variable or system property in spring tests?

    145 I'd like to write some tests that check the XML Spring configuration of a deployed WAR. Unfortunately some beans require that some environment variables or system properties are …

  5. Spring Test & Security: How to mock authentication?

    I was trying to figure out how to unit test if my the URLs of my controllers are properly secured. Just in case someone changes things around and accidentally removes security settings. My …

  6. How do I mock an autowired @Value field in Spring with Mockito?

    You can use the magic of Spring's ReflectionTestUtils.setField in order to avoid making any modifications whatsoever to your code. The comment from Michał Stochmal provides an …

  7. spring mvc - Load different application.yml in SpringBoot Test

    Aug 2, 2016 · If you are specifying the application-test.yml and provide the spring test profile in the .yml, then you can use the @ActiveProfiles('test') annotation to direct spring to take the …

  8. java - Spring JUnit: How to Mock autowired component in …

    90 I've got a Spring component I'd like to test and this component has an autowired attribute which I need to change for the purpose of unit testing. The problem is, that the class uses the …

  9. How can Spring's test annotation @Sql behave like @BeforeClass?

    Dec 12, 2017 · 5 Edit: As of Spring 6.1, around October 2023, there are 2 new execution modes: BEFORE_TEST_CLASS and AFTER_TEST_CLASS If you're using a version before that, my …

  10. java - Overriding beans in Integration tests - Stack Overflow

    Mar 2, 2016 · Spring will keep both (or how many contexts you have) in cache. Our build is this way, where most of the tests are using default non-poluted config, but we have 4-5 tests that …