4

We have an application that uses weld-se for CDI. For our JUnit tests, we fire up a new weld container using the following trick: WeldJUnit4Runner

Since we have a lot of tests, running them gets to take a long time every time Weld has to startup and initialize itself. Is there any way to "reset" weld, so that we can get a fresh WeldContainer without Weld having to re-scan the whole classpath every time?

Kricket
  • 4,049
  • 8
  • 33
  • 46

2 Answers2

3

Short answer: simply stop your open contexts.

Detailed answer: a great and easy way of using the Weld Se for testing purposes (unit test) offers DeltaSpike project from Apache itself http://deltaspike.apache.org/.

Currently I'm also participating in the development of a open source project which offers you a convenient way of testing your Java EE App with all the container services directly in the unit test via a JUnit Runner. https://github.com/NeoMorpheus/BeanTest

Also have a look at jglue.org/cdi-unit-user-guide/

Jens Piegsa
  • 7,399
  • 5
  • 58
  • 106
0

If you're able to sacrifice isolation for speed, have a look at the Weld Test Container of Pax Exam.

This does not reset Weld between tests, but as long as all your tests are in the same library/project/Maven module, Weld gets started only once for the entire test suite.

See Getting Started With CDI Tests.

Harald Wellmann
  • 12,615
  • 4
  • 41
  • 63