cdi-test is available under the The Apache Software License, Version 2.0
If you're developing Jakarta EE (Java EE) or just plain CDI applications or libraries you'll probably want to unit test your code. If you don't you really should. With cdi-test there's no excuse not to do it ;-)
As CDI doesn't come with any "standard" unit test capabilities you need some way to test your components in your JUnit 5 tests. This is not easily accomplished especially when compared with the junit integration of Spring Boot.
cdi-test is targeted at running unit, component and integration tests at scale. It accomplishes this with:
- Only booting the cdi container once for all unit tests. This allows for running a huge number of tests even in big projects where booting might take some time.
- cdi-test uses Weld (the cdi reference implementation) as cdi container. So you can use the exact same cdi container as in your application runtime in case you're running e.g. Wildfly, JBoss EAP, GlassFish or Oracle WebLogic.
- cdi-test supports mocks and test alternatives for CDI beans. These can be activated per test class. So you can freely choose what you want to test and need to mock test-by-test.
- Well tested and maintained and used in real projects with thousands of unit tests.
- CDI 2 and CDI 3 with the relevant releases of Weld
- Java 8+
- Jakarta EE 8
and Jakarta EE 9 (The new namespace introduced with Jakarta EE 9
will be supported starting with release 4.x. Pre-releases are already available.)
- Includes using EJBs with some restrictions. Injection and creation of
@Stateful
and@Stateless
ejbs. - Supports JPA even with multiple persistence units. Inject EntityManager
via
@Inject
or@PersistenceContext
.
- Includes using EJBs with some restrictions. Injection and creation of
- JUnit 5 (starting with cdi-test 3.x)
- Microprofile Config 2.x and 3.x
- Supports injecting test specific properties using annotations.
- Mockito is supported and used internally.
Most basic:
Using mocks:
See the Documentation on github pages.
Contribution guidelines for this project
Copyright 2015 Gunnar Hilling
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 at
http://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.
JProfiler supports open source projects with its full-featured Java Profiler. Click the JProfiler logo below to learn more.