spring-projects / spring-projects/spring-boot
Investigate methods of restarting applications for faster TDD
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 81.5k
- Forks
- 42.7k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 65
Description
This is a feature-request.
Any non-trivial (web + any datastore) spring boot application would have a 10s seconds startup time, most of them around 1 minute, and some extreme cases reach to 2 minutes. This is obviously a huge blocker for any flavor of test driven development work-style. Anything beyond a few seconds to run the test and get a feedback on my changes makes the TDD style impossible to employ. I'm sure many smart people already thought and pointed out this but the fact that no official solution or recommended pattern is known (to the best of my knowledge) is surprising to me.
Here's the use case: I would like to employ a TDD approach; one line of test code, run the test, one line of production code, run the test, repeat with minimal waiting time for Spring context to start.
Solutions
One solution is to keep the context light. I'm pretty sure there's a limit to this and very quickly it hits the ceiling in terms of startup performance optimization.
A better solution is to start the application once (in the IDE or in command line using Gradle for example) and start coding. Having the DevTools, production codes are reloaded automatically very quickly and test code can be executed as many times as needed considering that now the we don't have to wait for the context to start. I've created a proof of concept here.
Proposal (Draft)
SpringBootTestApplication Annotation
How to use it: Add it to a (non-test) class in the test folder which effectively makes the class a spring boot application and use the class as the configuration class in SpringBootTest annotation wherever the context is needed.
What it does: when added to a class, creates a very thin Spring Boot application in which it creates the main application (or a slightly different version of it with respect to main application configurations) as a bean.
Vision for the feature
- Create a thin spring boot application (container for the under-test main application)
- Create the under-test main application with the given custom configurations and properties (to make the main application testable, like mocks, etc)
- Propagate environments, profiles, and properties from the test to the under-test application. (whatever that means!)
- Provide an easy way to access beans defined in the under-test main application (e.g. JDBC DataSource)
- Handle shared resource properly between different instances of under-test main application (e.g. ports, test-containers, etc) if the user requires more than one version of the main application in different tests.
Notes
- Maybe the same functionality can be achieved by child context, but I'm not sure how much it'd be IDE and Gradle/Maven friendly. This definitely is an objective for this feature in my eyes.
I'd be happy to work on the feature, but for sure needs help with some of the internal code of Spring Boot Test module.
Thanks.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in Spring Boot's Test module and review SpringBootTest, the proposed SpringBootTestApplication annotation, and the linked proof of concept. Compare the child-context, DevTools, and IDE/Gradle/Maven approaches before defining scope; the issue does not specify tests or a concrete completion criterion.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring-boot
- Domain
- developer-experience, testing
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100