JUnit

How to inject mock into CDI context with Arquillian behind the scenes

 

My goal was to mock database, so every component in CDI based application would use mock instead of original implementation. I also had to have possibility to control my mock in JUnit test runtime. I struggle with this problem almost whole day and finally found satisfying solution :)

Not all steps are necessary, but I strongly encourage You to follow all of them.

1. Create stereotype for your mocked objects

2. Register newly created stereotype

3. Create mock factory

4. Write unit test

 

How to deploy arquillian EAR package to remote server with all required dependencies

If you want to test your enterprise package with arquillian, here is my way how to do it:

0. Prerequisites

  1. Maven multimodule project
  2. application server (I’ve used Weblogic 12c)

1. Add required maven dependencies to projects:

 

 2. Create base test class

Note that all required dependencies and test classes are included in the package, so  NoClassDefFoundException will not bother you anymore ;)

3. Add arquillian.xml descriptor to src/test/resources

  3. Write a test