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

 

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

  1. Benni says:

    Wow, thank you really much. I tried to get different values from the same producer for hours, but with your way this works like a charm :-)

Leave a Reply


× 3 = three