Got it, really appreciate your detailed demo, thanks.:)
On Sep 23, 6:15 pm, leszek <[email protected]> wrote:
> You need to have your data access method separated from servlet code
> or RPC (if GWT is used) code.
>
> Assume that you have something like:
>
> class Customer {
>
> private Key customerId;
> ...
>
> }
>
> class MyDataAccessService {
>
> public void addCustomer(Customer c) {
> ...
> }
>
> and you want to test it.
>
> You can create separate project for test (and link sources with main
> project) or you can have test packages together with the main project.
>
> So you write your test case (assuming Junit4)
>
> public class TestCase1 {
>
> ...
> @Test
> public void testAddingCustomer() {
> Customer c = new Customer();
> c.setCustomerId("google");
> ...
> MyDataAccessService service = new MyDataAccessService();
> service.addCustomer(c);
> // now test
> PersistenceManager pm = ...
> Customer c1 = pm.getObjectById(Customer.class, "google");
> assertNotNull(c1);
> assertEquals("google",c1.getCustomerId);
> ..
>
> }
>
> Now you want to have this test enabled for local Google App Engine
> environment.
>
> Create classes us described under link and fix your test case.
>
> http://code.google.com/appengine/docs/java/howto/unittesting.html
>
> public class TestCase1 extends LocalDatastoreTestEnvironment {
>
> �...@before
> public void setUp() {
> super.setUp();
> }
>
> �...@after
> public void tearDown() {
> super.tearDown();
> }
>
> �...@test
> public void testAddingCustomer() {
> ..
>
> }
>
> Now you can run TestCase1 as standard Junit Test (from Eclipse) and be
> happy.
>
> Addtional remark:
> You can avoid extending your TestCase and use simple composition.
>
> class TestCase {
>
> LocalDatastoreTestEnvironment localStore = new
> LocalDatastoreTestEnvironment();
>
> �...@before
> public void setUp() {
> localStore.setUp();
> }
>
> �...@after
> public void tearDown() {
> localStore.tearDown();
> }
>
> Also you can change it anyway as you like and best fit to your
> purpose.
>
> Treat what is under link as a demo how this stuff is running, not as a
> dogma.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---