Results 1 to 3 of 3

Thread: Spring roo and Unit Testing with Mock Objects

  1. #1
    Join Date
    Jun 2009
    Posts
    26

    Default 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. #2
    Join Date
    Oct 2007
    Posts
    16

    Default 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();

  3. #3
    Join Date
    Jun 2005
    Location
    São Paulo, Brasil
    Posts
    86

    Default

    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.
    Simplicity is prerequisite for reliability. — Edsger W. Dijkstra

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •