entitymanager

How to mock EntityManager?

让人想犯罪 __ 提交于 2020-12-30 04:50:07
问题 I need to mock entity-manager to make testing service layer (in my case a session facade) to be independent of the underlying layer (which in my case is the entity-manager). So how I can accomplish this? Should I use dbunit? Do I need easy/j(Mock)? 回答1: I suggest to use Mockito Framework it is very easy to use and understand. @Mock private EntityManager entityManager; If you want to use any method that belongs to entityManager, you should call. Mockito.when(METHOD_EXPECTED_TO_BE_CALLED)

How to mock EntityManager?

你。 提交于 2020-12-30 04:49:43
问题 I need to mock entity-manager to make testing service layer (in my case a session facade) to be independent of the underlying layer (which in my case is the entity-manager). So how I can accomplish this? Should I use dbunit? Do I need easy/j(Mock)? 回答1: I suggest to use Mockito Framework it is very easy to use and understand. @Mock private EntityManager entityManager; If you want to use any method that belongs to entityManager, you should call. Mockito.when(METHOD_EXPECTED_TO_BE_CALLED)