-
Notifications
You must be signed in to change notification settings - Fork 12
Quick Start
This section makes you quickly comfortable with the concepts and the API design of CDI BeanTesting.
In order to add CDI BeanTesting to a Maven-based project, put the following snippets to your pom.xml file
Novatec Maven Repository
<repository>
<id>Novatec</id>
<name>Novatec Repository</name>
<url>http://repository.novatec-gmbh.de/content/repositories/novatec</url>
</repository>CDI BeanTesting Dependency
<dependency>
<groupId>info.novatec</groupId>
<artifactId>bean-test</artifactId>
<version>{currentVersion}</version>
<scope>test</scope>
</dependency>Alternatively, binaries can also be found at http://repository.novatec-gmbh.de/content/repositories/novatec/info/novatec/bean-test/
There are just a few things which need be to configured.
- Create an empty beans.xml file (marker file for the CDI Bean container) under 'src/test/resources/META-INF'.
- Created a persistence.xml file in 'src/test/resources/META-INF'.
- Create a persistence unit called "beanTestPU" in the created persistence.xml file.
Note: Import statements are intentionally missing.
First things first. Lets create a simple component:
public class ServiceOfWisdom {
@Inject Instance<String> answer;
public String getAnswer() {
return answer.get();
}
}
public class AnswerProducer {
@Produces final static String answer = "42";
}Now create a JUnit test class for the service:
public class TestServiceOfWisdom extends BaseBeanTest {
@Test
public void test_if_service_is_successfully_injected() {
ServiceOfWisdom service = getBean(ServiceOfWisdom.class);
assertThat(service, is(notNullValue()));
assertThat(service.getAnswer(), is("42"));
}
}You can either run the test as commonly practised in your favourite IDE as a normal JUnit test or via Maven.
CDI BeanTesting provides straightforward debugging functionality.

