https://github.com/cdi-unit/cdi-unit
Unit testing for CDI applications
https://github.com/cdi-unit/cdi-unit
cdi-injection deltaspike junit4 junit5 spock-framework testng unit-testing
Last synced: about 2 months ago
JSON representation
Unit testing for CDI applications
- Host: GitHub
- URL: https://github.com/cdi-unit/cdi-unit
- Owner: cdi-unit
- License: apache-2.0
- Created: 2011-04-26T21:20:52.000Z (almost 14 years ago)
- Default Branch: master
- Last Pushed: 2025-02-23T11:41:30.000Z (about 2 months ago)
- Last Synced: 2025-02-23T12:26:34.157Z (about 2 months ago)
- Topics: cdi-injection, deltaspike, junit4, junit5, spock-framework, testng, unit-testing
- Language: Java
- Homepage: http://cdi-unit.github.io/cdi-unit/
- Size: 1.65 MB
- Stars: 97
- Watchers: 14
- Forks: 57
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Support: support-servlet/pom.xml
Awesome Lists containing this project
- awesome-java - CDI-Unit
README
cdi-unit
========Unit testing for CDI applications. Supports Mockito for mocking dependencies.
See website for full details http://cdi-unit.github.io/cdi-unit
Discussion can be found here https://groups.google.com/forum/#!forum/cdi-unit
[](https://search.maven.org/artifact/io.github.cdi-unit/cdi-unit/)
[](https://javadoc.io/doc/io.github.cdi-unit/cdi-unit)## Getting the latest release
[CDI-Unit 5](https://github.com/cdi-unit/cdi-unit/TBD)
- Supports CDI 3.x+ (`jakarta.` packages)
- Requires Java 11[CDI-Unit 4](https://github.com/cdi-unit/cdi-unit/releases/tag/cdi-unit-parent-4.4.0)
- Supports CDI 1.x or 2.x (`javax.` packages)
- Supports Java 8 and Java 11Only one major version is supported at a time, and changes are not backported to older versions.
```xml
io.github.cdi-unit
cdi-unit
${cdi-unit-version}
test```
## Example unit test
```java
class Starship {@Inject
Engine engine; //We don't know the exact engine that this ship will have.void start() {
engine.start();
}
}@RunWith(CdiRunner.class)
@AdditionalClasses(WarpDrive.class) // WarpDrive is available to use.
class TestStarship {@Inject
Starship starship;@Test
public void testStart() {
starship.start(); // Going to warp!
}
}```
### Acknowledgements
This project uses code shamelessly copied from:[Mockrunner](https://github.com/mockrunner/mockrunner) under Apache license.
[Resteasy](http://resteasy.jboss.org/) under Apache license.### License
```text
Copyright 2013 CDI-Unit contributors.Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```