79654210

Date: 2025-06-05 10:02:23
Score: 2
Natty:
Report link

Arquillian is not meant to be used with Mockito.

You should work with an @Alternative which has to be added to an Arquillian @Deployment.

Even the official Jakarata CDI Spec reveals this way: It declares the @Mock Stereotype, which bundles @Alternative and @Priority:

@Alternative
@Priority(value = 0)
@Stereotype
@Target(TYPE)
@Retention(RUNTIME)
@interface Mock { }
@Mock
@Stateless
class MyFacesContext extends jakarta.faces.context.FacesContext {...}
@ExtendWith(ArquillianExtension.class)
class ArquillianTest {
    @Deployment
    static WebArchive createDeployment() {
        return ShrinkWrap.create(WebArchive.class).addClasses(MyFacesContext.class);
    }
    
    @Inject
    FacesContext facesContext;

    @Test
    void testMock() {
        assertNotNull(facesContext)
    }        
}

There exist Libraries which try to associate Mockito with Arquillian like:

Their implementation missuses Mockito in some way.

Moreover it's not the way Jakarta EE thinks.

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @Alternative
  • Low reputation (1):
Posted by: rudi1602