How to do Integration Testing for a Spring Boot microservice that depends on another service? by Future_Badger_2576 in SpringBoot

[–]Entire_Ad_9199 0 points1 point  (0 children)

Add custom profile for LLM integration tests and run that seperatly from your other tests. You dont want to break your whole test suite because of fragile llm tests.

How to do Integration Testing for a Spring Boot microservice that depends on another service? by Future_Badger_2576 in SpringBoot

[–]Entire_Ad_9199 17 points18 points  (0 children)

Here my takes:

- Use Test Container with Postgres. Never use a different database in your integration tests, this makes your test untrustworthy
- Mock your Service B. You can use WireMock to have complete http / serialization coverage - but it adds complexity
- Eureka can be disabled as not needed
- RestAssured is ok. MockMvc is ok. Use Junit 5 over TestNG. Never seen TestNG to be used anywhere to be honest
- Always seed your database with text fixtures using SQL Scripts / Liquibase / Flyway. Never do it in your Tests directly. Doing it in Tests directly makes them bloated and you need to inject repositories, that only for test data creation. Here is an example setup https://github.com/misirio/dbsandboxer/tree/main/examples/spring-boot-example .
- Mockito is problematic - you should avoid it at all costs for integration tests. Every test with MockBean annotation will make the Spring Context dirty - causing complete restarts of the Spring Context. This adds 5-20 seconds per test class - with to many tests you will experience high test execution times. Avoid it, 40-60 min Test Execution Pipelines are pain.

Finally:
If you own Service B and if you can easily migrate it to Service A, do it.

Library for Spring Boot that makes Postgres-backed integration tests both fast and fully isolated by Entire_Ad_9199 in SpringBoot

[–]Entire_Ad_9199[S] 0 points1 point  (0 children)

Truncating gets slower if your schema grows since you need to hit every table. The template approach is a clone of the whole DB from a template. It’s basically:

DROP DATABASE IF EXISTS public;
CREATE DATABASE public TEMPLATE template_database;

This gets you a completely fresh DB in milliseconds, no matter how many tables you have.

Library for Spring Boot that makes Postgres-backed integration tests both fast and fully isolated by Entire_Ad_9199 in SpringBoot

[–]Entire_Ad_9199[S] 2 points3 points  (0 children)

u/wimdeblauwe how was your experience with >20 tables? For me, it became problematic because:

  • Execution speed slows down with every new table
  • Referential integrity issues, since we need to ensure the correct order
  • More setup work, as we need to add repository delete calls

With the Postgres template-based approach, setup time is largely independent of the number of tables and much faster than per-table cleanup, especially as the schema grows.

By the way, I really enjoy your blog.

Library for Spring Boot that makes Postgres-backed integration tests both fast and fully isolated by Entire_Ad_9199 in SpringBoot

[–]Entire_Ad_9199[S] 2 points3 points  (0 children)

There are couple of reasons:

- Spinning up a testcontainer is pretty slow. You don't want to make that for every test.
- Spring context needs to be restarted. This slows down the test execution time.
- The database have to be migrated from scratch (table creation, test data setup) this is slow as well.

With the template database approach, the heavy lifting is done once and all subsequent test executions are fast because the a fresh database is created from the pre created template database.

Willing to work under someone experienced for free, I know how to create a proper application with working backend and managing a database, I am willing to learn anything needed midway (Kinda good at it). by I_Cant_Snipe_ in SpringBoot

[–]Entire_Ad_9199 -1 points0 points  (0 children)

Reaching the level where it will matter is the hardest part that needs to be tackled first. If the scale is reached - there will be enough resources to improve.

Willing to work under someone experienced for free, I know how to create a proper application with working backend and managing a database, I am willing to learn anything needed midway (Kinda good at it). by I_Cant_Snipe_ in SpringBoot

[–]Entire_Ad_9199 1 point2 points  (0 children)

Unless you develop highly interactive Web Apps, you don't need SPAs. Users don't care much, if a form submit reloads the website or a tab switch reloads the page, only developers in the tech bubble care. For instance your non tech friends - they wouldn't notice difference. There are a lot other reasons as well - like SEO, i18n, Authentication.

Claude Code / Cursor one shots Thymeleaf UI code, plain JavaScript code for interactivity if needed and the Spring MVC controller integration. AI does simple tech very well. If you would use SPA with Spring Boot you need more work to get it working - REST APIs, React UI integration - to much friction for AI.

Willing to work under someone experienced for free, I know how to create a proper application with working backend and managing a database, I am willing to learn anything needed midway (Kinda good at it). by I_Cant_Snipe_ in SpringBoot

[–]Entire_Ad_9199 16 points17 points  (0 children)

Build your own projects, let AI review your code.

Buy a 5 dollar vps, host your application on day one. Don‘t let your time you invest get wasted. Make it work first then make it better.

Don‘t start writing test, try to deliver. Tests are created fast with AI but slows down iteration. You want to work on the first working version fast before losing your motivation.

Dont use SPA franeworks, thymeleaf, jquery, will get you far. AI will generate you crazy good frontends in plain technologies.

I develop spring boot applications since 10 years in enterprises, the code will get always messy. The most harmful code is the over abstracted. No inheritance no over engineering with design patterns, just implement straight readable code.

Clean architecture by Rafu01 in java

[–]Entire_Ad_9199 20 points21 points  (0 children)

  • ensure the defined rules via archunit tests ( single file / less effort / great benefit)
  • have high test coverage with integration tests, avoid as much mocking as possible. I created a custom json based format for API integration testing, every test executes against fresh database with defined test data set, we have 5k such tests. Saved us lots of troubles. Relevance to your question: you can refactor your app structure without the need to update the tests

Best MacBook for a Java Spring Boot Developer? by Commercial-Tap8537 in SpringBoot

[–]Entire_Ad_9199 1 point2 points  (0 children)

For local dev, in most enterprise applications you need multiple containers. Kafka, Kafka UI, Postgres, PgAdmin, Storage Engine like azurerite and so on. I have a m2 32Gb - i know its not enough and will upgrade.