jeudi 9 juillet 2015

TestNG unit test not working after annoting service to test with @Retention, @Transactional, @Interited

I am testing my business service with TestNG, mockito unit tests in spring boot application.

My annotation to service look like

@Service
@Transactional
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface MyService{}

My TestApp looks like

@SpringBootApplication
public class TestApp
{ .... }

MyTestClass looks like

@ContextConfiguration(classes = { TestApp.class })
class MyTestClass
{ 
    @Mock ....
    @InjectMocks .....

    @BeforeMethod
    public void initMock()
    {
        MockitoAnnotations.initMocks(this);
    }
}

If I don't use @Target(ElementType.TYPE), @Retention(RetentionPolicy.RUNTIME), @Inherited these annotations then my mock DAO calls in test works fine

BUT when I use above annotations then mock DAO calls does not works.

  1. Why this is not working ?
  2. What would be the solution over it ?

Your response is appreciated !!

Aucun commentaire:

Enregistrer un commentaire