Questions tagged [cdi-unit]

CDI-Unit is a JUnit 4 and TestNG test runner that enables unit testing Java CDI applications.

CDI-Unit is a JUnit 4 and TestNG test runner that enables unit testing Java CDI applications.

The tests run outside of a web container. The configuration is performed in the unit test class using annotations.

20 questions
7
votes
1 answer

CdiUnit test with Junit @Rule is impossible because of a public private field paradox

The following snippet is enough to reproduce my problem: Either I set the thrown attribute public and get the error org.jboss.weld.exceptions.DefinitionException: WELD-000075: Normal scoped managed bean implementation class has a public field Or I…
Aldian
  • 2,592
  • 2
  • 27
  • 39
5
votes
2 answers

Injection of @PersistenceContext in CDI-Unit

Here is the unit testing code. When we run unit test code (SampleServiceTest2); EntityManager injected in AbstractDao is always null! How can we inject em during unit test. *** SampleServiceTest2.java import javax.inject.Inject; import…
fatihn
  • 137
  • 1
  • 8
3
votes
1 answer

Java EE JUnit not working with CDI-Unit while using EJBs

I'm using the CDI-Unit JAR http://jglue.org/cdi-unit/ to be able to use CDI in my JUnit 4 tests, I've injected my EJB and called a method to persist a Client object, but I get the following error : java.lang.NoClassDefFoundError…
Dwix
  • 1,139
  • 3
  • 20
  • 45
3
votes
1 answer

How to exclude classes from scanning with CDI-unit?

I am running tests with CDI-unit runner and want some classes to be excluded (because they act on CDI events). I tried beans.xml:
mmm
  • 1,688
  • 16
  • 35
3
votes
2 answers

Cannot inject EntityManager declared in persistence.xml

I'm trying to develop a (Maven-based) jar library which can act as a DAL for my Java application. This is my persistence.xml file
gvdm
  • 3,006
  • 5
  • 35
  • 73
3
votes
3 answers

Unit testing CDI with CDI-Unit Jglue

we want to use Jglue framework for unit testing our CDI application. We use gradle for building. We have prepared something like this: 1) Class to test: @Default public class RateTypeHibernateFactory implements RateTypeFactory { @Override public…
3
votes
3 answers

unit test with CDI Unit and EasyMock

I have a project with CDI and I would like to create unit test with mocks. To manage mocks, I would like to use EasyMock and to run with CDI, I find the cdi-unit project which seem easy to use. I have a problem to get a mock with EasyMock in CDI…
Kiva
  • 9,193
  • 17
  • 62
  • 94
2
votes
0 answers

Unit testing an application with CDI and ServletContextListener

I've got a CDI web application which has a ServletContextListener to initialise a few things on startup. In that ServletContextListener, this (among other things) happens: @Inject Config config; public void contextInitialized(ServletContextEvent…
Steven De Groote
  • 2,187
  • 5
  • 32
  • 52
2
votes
1 answer

Activiti CDI / Weld SE / CDI unit

Has anyone ever tried to test Activiti / BPMN processes using pure CDI? In theory (if I didn't miss anything) I would think it should be possible to use f.ex. cdi-unit for testing processes together with activiti-engine and activiti-cdi. CDI unit…
cslotty
  • 1,696
  • 20
  • 28
2
votes
1 answer

Unit test with WicketTester and CDI-Unit works in Eclipse but fails during Maven build. What am I missing?

I am trying out using CDI-Unit to test my Wicket components, which are using CDI for dependency injection. Tests seems to work perfectly in Eclipse but fail during my Maven build and I cant seem to find any hints and what is wrong. I have created a…
Jesper Tejlgaard
  • 827
  • 10
  • 16
1
vote
0 answers

cdi-unit tests failing with recent maven-failsafe-plugin versions

After updating maven-failsafe-plugin from 2.18.1 to version 2.22.2, cdi-unit (4.1.0) tests started to fail with the error: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type Validator with qualifiers…
g6380647
  • 267
  • 1
  • 2
  • 10
1
vote
1 answer

Weld class not found when executing cdi-unit test

I have a JEE project that is deployed on wildfly 10 smoothly. I'm trying to write junit tests for my CDI beans with cdi-unit library (http://bryncooke.github.io/cdi-unit/) My pom.xml looks like the following:
user711189
  • 4,383
  • 4
  • 30
  • 48
1
vote
1 answer

CDI, cdi-unit. Exception trying inject interface

I test class using cdi-unit library. Test class: @RunWith(CdiRunner.class) public class IAktResponseMapperTest { @Inject private ITestCDI testCDI; @Test public void testCDI(){ testCDI.testCDI(); } } ITestCDI…
1
vote
1 answer

Expected? CDI Request scoped bean injected into producer injected into dependent bean gives WELD-001303: No active contexts

Assume that the RequestScope is active (Using cdi-unit's @InRequestScope) Given package at.joma.stackoverflow.cdi; public class Product { public Product(String withValue){ this.value = withValue; } public String…
Joerg M.
  • 397
  • 2
  • 12
1
vote
1 answer

CDI-Unit @Produces not working

First off I googled intensively and according to http://jglue.org/cdi-unit-user-guide/ producing stuff to inject in a unit test should work just fine. My setup: @RunWith(CdiRunner.class) public abstract class CdiUnitBaseTest extends DBUnitBaseTest…
Thomas
  • 624
  • 11
  • 28
1
2