Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

A quick guide to Spring Tests optimization

Pragya Keshap answered on February 11, 2023 Popularity 1/10 Helpfulness 1/10

Contents


More Related Answers

  • Junit, Server level Spring boot tests
  • Example Of Spring Boot Test
  • How to test Java Spring Boot application without @SpringBootApplication using JUnit?
  • spring boot testing strategies
  • First principles in Spring Boot Testing
  • Optimizing Spring Integration Tests
  • Spring Boot performance tuning
  • Junit question- springbootTest, How you mock dependency
  • Testing the Entire Application With @SpringBootTest
  • Summary of the Spring Boot Starter Test
  • How does Spring Framework Make Unit Testing Easy?

  • A quick guide to Spring Tests optimization

    0

    Try to use JUnit instead of Gradle to run tests, mostly if you are running simple suites and you want to know the result faster

    Initializing the Spring context is not cheap, do it only if it's necessary. The usage of annotations like @SpringBootTest is generally associated with Integration tests, and to avoid falling into the Ice Cream Cone anti-pattern, it is recommended to have more unit tests than integration tests, so don't put @SpringBootTest annotation everywhere

    If you are using @SpringBootTest, try to reuse the context as much as you can, avoiding the anti-patterns I've mentioned before and doing some research if you see that it's not being reused and you are not using the annotations I said (to understand in which tests the Spring Context is being initialized, you should look in which test class the SPRING logo appears)

    Use mocks only if it’s necessary, for example in case the context is difficult to reproduce. Don’t mock everything because you won’t end up testing anything at all.

    https://blog.10pines.com/2022/05/20/a-quick-guide-to-spring-tests-optimization/

    Popularity 1/10 Helpfulness 1/10 Language typescript
    Source: Grepper
    Link to this answer
    Share Copy Link
    Contributed on Feb 11 2023
    Pragya Keshap
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.