apache / apache/grails-core

No Session found for current thread in spring boot test

Open
#14,351 4 comments 0 reactions 0 assignees View on GitHub
relates-to: grails-data-hibernate5
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

When using @SpringBean in different SpringBootTest, spring will create a separate context for each test since spring doesn't know if those two tests share the same mock beans. This caused "No Session found for current thread" when running two tests together.

Please clone the following repo to reproduce it.
git@github.com:ruiyang/gorm-spring-boot-hibernate-session-error.git
or
[https://github.com/ruiyang/gorm-spring-boot-hibernate-session-error](https://github.com/ruiyang/gorm-spring-boot-hibernate-session-error)

There are two tests:
VehicleServiceTest
ManufacturerServiceTest

test passes when running each individually
```
./gradlew test --tests *ManufacturerServiceTest*
./gradlew test --tests *VehicleServiceTest*
```

test will fail when running together

`./gradlew test`

Please help!
Thanks

Contributor guide

Open the contributing guide

Research direction

Clone the linked reproduction repository and inspect VehicleServiceTest and ManufacturerServiceTest. Run each test separately with the provided Gradle commands, then run ./gradlew test to reproduce the combined failure. Done means identifying and resolving the cause of "No Session found for current thread" when both tests run together.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy, spring-boot
Domain
backend, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.