You could get more information on the way we set up our testing infra
here

http://thoughts.inphina.com/2010/06/28/unit-testing-maven-based-jpa-application-on-gae/

Regards | Vikas
www.inphina.com

On Nov 10, 2:37 pm, lp <[email protected]> wrote:
> hi all,
>
> i have been attempting to convert my existing JPA code over to GAE.
>
> All is working so far except for the unit tests.
>
> i read
> code.google.com/appengine/docs/java/tools/localunittesting.html
>
> but it doesnt describe how to get an entityManager involved in usefull
> unit tests.
>
> so this is my test. please advise how to achieve the functionality in
> this test.
>
> @Test
> public void findFriendsSimple() {
>
> PositionUser user1 = new PositionUser();
> user1.setFirstName("john");
> user1.setLastName("smith");
>
> PositionUser user2 = new PositionUser();
> user2.setFirstName("mary");
> user2.setLastName("smith");
>
> PositionUser user3 = new PositionUser();
> user3.setFirstName("barney");
> user3.setLastName("smith");
>
> em.persist(user2);
> em.persist(user3);
> //em.flush(); <--- can use flush for non transaction test
>
> user1.getFriends().add(user2.getKey());
> user1.getFriends().add(user3.getKey());
>
> em.persist(user1);
> //em.flush(); <--- can use flush for non transaction test
>
> Query query = em.createNamedQuery(PositionUser.FIND_FRIENDS);
> query.setParameter("userKey", user1.getKey());
> List resultList = query.getResultList();
> assertEquals( 2, resultList.size() );
>
> }
>
> the assert is triggered
> java.lang.AssertionError: expected:<2> but was:<0>
>
> this is because the entitymanager wont detect the persisted entities
> that arent in a transaction.
>
> ok no problem, i will add transactions.
>
> But when i do it complains that i am adding multiple groups in a single
> transaction.
>
> So besides the simple gae sample unit test, how are others writting
> useful unit tests in gae?
>
> any help is most appreciated
>
> -lp

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to