Announcement Announcement Module
Collapse
No announcement yet.
Spring roo and Unit Testing with Mock Objects Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring roo and Unit Testing with Mock Objects

    I am trying to figure out how to properly write unit tests with Spring roo generaged Entity classes. I understand how to handle the static methods on Entity objects by using the @MockStaticEntityMethods, however, what I don't understand is how to deal with persist(). Since your running in a JUNIT test the injection of the entitymanager does not occur and I don't see away to manually inject the entitymanager with a mock. Can anyone shed any light on to this if I am making any since?

  • #2
    Spring roo and Unit Testing with Mock Objects

    What I have been doing is to use EasyMock to create a mock of the entity manager, something like this:

    // easy mock
    EntityManager entityManager = createMock(EntityManager.class)
    entityManager.persist(eq(expected));
    replay(entityManager);

    // static mocks
    MyEntity.entityManager();
    expectReturn(entityManager);
    playback();

    Comment


    • #3
      I'd love for more people to chime in on this thread, I've found unit testing in Spring Roo to be harder than I expected.

      Comment

      Working...
      X