https://github.com/qaware/spock-cdi-example
Example tests with Spock and CDI for integration tests
https://github.com/qaware/spock-cdi-example
Last synced: about 1 year ago
JSON representation
Example tests with Spock and CDI for integration tests
- Host: GitHub
- URL: https://github.com/qaware/spock-cdi-example
- Owner: qaware
- License: mit
- Created: 2020-11-17T07:49:42.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-11-17T12:48:14.000Z (over 5 years ago)
- Last Synced: 2024-12-25T16:42:20.198Z (over 1 year ago)
- Language: Groovy
- Size: 66.4 KB
- Stars: 0
- Watchers: 6
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Spock CDI Example
Example project to demonstrate CDI injection into Spock Specs, including mocking of individual CDI beans per Spec.
There is no need to list all the beans to use in the test.
## CDI implementation
This project supports WELD and OpenWebBeans. It uses WELD by default.
To run the tests with OpenWebBeans instead, run: `./gradlew build -PuseOpenWebBeans`
## Findings
- OpenWebBeans requires that all beans have a no-args constructor, even if fields are injected via constructor
- WELD requires that the beans.xml and the classes are in the same folder,
but Gradle puts resources and classes into separate folders by default (for test executions).
A workaround is applied in [build.gradle.kts](build.gradle.kts).
- Repeatedly creating the CDI context takes much longer with OpenWebBeans (see [CdiContextConstructionSpec](./src/test/groovy/spock/test/CdiContextConstructionSpec.groovy)).