Testing Your Application On Google App Engine
-
Upload
indicthreads -
Category
Technology
-
view
454 -
download
3
Transcript of Testing Your Application On Google App Engine
![Page 1: Testing Your Application On Google App Engine](https://reader031.fdocuments.us/reader031/viewer/2022030308/58f36fb11a28abcb0f8b457b/html5/thumbnails/1.jpg)
1
Testing Your Application on / for Google App Engine
Narinder KumarInphina Technologies
![Page 2: Testing Your Application On Google App Engine](https://reader031.fdocuments.us/reader031/viewer/2022030308/58f36fb11a28abcb0f8b457b/html5/thumbnails/2.jpg)
2
Agenda
Problem Context App Engine Testing Framework
Local DataStore Testing
Authentication API Testing
Memcache Testing
Google Cloud Cover – An Overview
![Page 3: Testing Your Application On Google App Engine](https://reader031.fdocuments.us/reader031/viewer/2022030308/58f36fb11a28abcb0f8b457b/html5/thumbnails/3.jpg)
3
Easy to build, Easy to Maintain, Easy to Scale
![Page 4: Testing Your Application On Google App Engine](https://reader031.fdocuments.us/reader031/viewer/2022030308/58f36fb11a28abcb0f8b457b/html5/thumbnails/4.jpg)
4
Why Testing To verify correctness
of the code To be assured of
continued correctness of old code
To avoid surprises To safely make large
refactoringsI feel sad and naked without Good Test Coverage
Max Ross (Member of Google App Engine Team)
![Page 5: Testing Your Application On Google App Engine](https://reader031.fdocuments.us/reader031/viewer/2022030308/58f36fb11a28abcb0f8b457b/html5/thumbnails/5.jpg)
5
Do we need App Engine Specific Testing Strategies ?
![Page 6: Testing Your Application On Google App Engine](https://reader031.fdocuments.us/reader031/viewer/2022030308/58f36fb11a28abcb0f8b457b/html5/thumbnails/6.jpg)
6
Our Goal
To be able to test in our local environment using Spring Maven JPA/JDO JUnit Continuous Integration
![Page 7: Testing Your Application On Google App Engine](https://reader031.fdocuments.us/reader031/viewer/2022030308/58f36fb11a28abcb0f8b457b/html5/thumbnails/7.jpg)
7
Google Infrastructure Services
DataStore Memcache TaskQueue Authentication ...
![Page 8: Testing Your Application On Google App Engine](https://reader031.fdocuments.us/reader031/viewer/2022030308/58f36fb11a28abcb0f8b457b/html5/thumbnails/8.jpg)
8
App Engine Testing Framework
LocalServiceTestHelper LocalDataStoreServiceTestConfig
LocalMemCacheServiceTestConfig
LocalTaskQueueTestConfig
LocalUserServiceTestConfig
...
![Page 9: Testing Your Application On Google App Engine](https://reader031.fdocuments.us/reader031/viewer/2022030308/58f36fb11a28abcb0f8b457b/html5/thumbnails/9.jpg)
9
Local Data Store Testing
![Page 10: Testing Your Application On Google App Engine](https://reader031.fdocuments.us/reader031/viewer/2022030308/58f36fb11a28abcb0f8b457b/html5/thumbnails/10.jpg)
10
Step 1 : Make RunTime Libraries Available Locally
<dependency><groupid>com.google.appengine</groupid><artifactid>appengine-testing</artifactid><version>1.3.4</version><scope>test</scope>
</dependency><dependency>
<groupid>com.google.appengine</groupid><artifactid>appengine-api-labs</artifactid><version>1.3.4</version><scope>test</scope>
</dependency><dependency>
<groupid>com.google.appengine</groupid><artifactid>appengine-api-stubs</artifactid><version>1.3.4</version><scope>test</scope>
</dependency>
Some of these libraries are not available in Central Maven Repositories
![Page 11: Testing Your Application On Google App Engine](https://reader031.fdocuments.us/reader031/viewer/2022030308/58f36fb11a28abcb0f8b457b/html5/thumbnails/11.jpg)
11
Step 2 : Enhance Domain Classes<plugin>
<groupid>org.datanucleus</groupid><artifactid>maven-datanucleus-plugin</artifactid><version>1.1.4</version><configuration><mappingincludes>**/domain/*.class</mappingincludes>
<verbose>true</verbose><enhancername>ASM</enhancername><api>JPA</api>
</configuration><executions>
<execution><phase>compile</phase><goals>
<goal>enhance</goal></goals>
</execution></executions>
......<plugin>
![Page 12: Testing Your Application On Google App Engine](https://reader031.fdocuments.us/reader031/viewer/2022030308/58f36fb11a28abcb0f8b457b/html5/thumbnails/12.jpg)
12
Prepare Run-Time Environment and Dependencies
@RunWith(SpringJUnit4ClassRunner.class)@TestExecutionListeners( { DependencyInjectionTestExecutionListener.class })@ContextConfiguration(locations = { "classpath:test-applicationContext.xml", "classpath:test-applicationContext-dao.xml"})public class LocalDatastoreSpringTestCase extends TestCase {
private final LocalServiceTestHelper helper = new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig());
@Before public void setUp() { helper.setUp(); }
@After public void tearDown() { helper.tearDown(); }
![Page 13: Testing Your Application On Google App Engine](https://reader031.fdocuments.us/reader031/viewer/2022030308/58f36fb11a28abcb0f8b457b/html5/thumbnails/13.jpg)
13
Write Specific Tests
public class EmployeeDaoSpringTest extends LocalDatastoreSpringTestCase {
@Autowiredprivate EmployeeDao employeeDao;
@Testpublic void testShouldPersistEmployee() {
Employee employee = new Employee();employee.setFirstName("Scott");employee.setLastName("Adams");employee.setHireDate(new Date());
employeeDao.createEmployee(employee);
Collection<employee> list = employeeDao.list();
Assert.assertEquals(1, list.size());}
![Page 14: Testing Your Application On Google App Engine](https://reader031.fdocuments.us/reader031/viewer/2022030308/58f36fb11a28abcb0f8b457b/html5/thumbnails/14.jpg)
14
Authentication API Testingpublic class AuthenticationTest {
private final LocalServiceTestHelper helper = new LocalServiceTestHelper(new LocalUserServiceTestConfig()) .setEnvIsAdmin(true).setEnvIsLoggedIn(true);
@Test public void testIsAdmin() { UserService userService = UserServiceFactory.getUserService(); assertTrue(userService.isUserAdmin()); }
@Before public void setUp() { helper.setUp(); }
@After public void tearDown() { helper.tearDown(); }}
![Page 15: Testing Your Application On Google App Engine](https://reader031.fdocuments.us/reader031/viewer/2022030308/58f36fb11a28abcb0f8b457b/html5/thumbnails/15.jpg)
15
Memcache Testingpublic class LocalMemcacheTest {
private final LocalServiceTestHelper helper = new LocalServiceTestHelper(new LocalMemcacheServiceTestConfig());
@Test private void testInsert() { MemcacheService ms = MemcacheServiceFactory.getMemcacheService(); assertFalse(ms.contains("yar")); ms.put("yar", "foo"); assertTrue(ms.contains("yar")); }}
.... // SetUp and Tear Down
![Page 16: Testing Your Application On Google App Engine](https://reader031.fdocuments.us/reader031/viewer/2022030308/58f36fb11a28abcb0f8b457b/html5/thumbnails/16.jpg)
16
Google Cloud Cover – An Overview
![Page 17: Testing Your Application On Google App Engine](https://reader031.fdocuments.us/reader031/viewer/2022030308/58f36fb11a28abcb0f8b457b/html5/thumbnails/17.jpg)
17
Key Features
Provides ability to run your tests in Cloud Designed to run Existing Test Suites Tests Execute in Parallel
Creates one Task Queue per Test
Number of workers determined by Queue Config
Allows to Run Large Test Suites faster : Acts as a Test Grid
![Page 18: Testing Your Application On Google App Engine](https://reader031.fdocuments.us/reader031/viewer/2022030308/58f36fb11a28abcb0f8b457b/html5/thumbnails/18.jpg)
18
How to Set it up
Create a Standard GAE/J web application with all Production Code & Test Code and dependencies
Add Cloud Cover Dependencies to WAR Create a TestRunner Config around your Test
Suite Add Cloud Cover Servlet
http://<your_app_id>/cloudcover.html
![Page 19: Testing Your Application On Google App Engine](https://reader031.fdocuments.us/reader031/viewer/2022030308/58f36fb11a28abcb0f8b457b/html5/thumbnails/19.jpg)
19
Google Cloud Cover in Action
![Page 20: Testing Your Application On Google App Engine](https://reader031.fdocuments.us/reader031/viewer/2022030308/58f36fb11a28abcb0f8b457b/html5/thumbnails/20.jpg)
20
Different from Normal Testing
Each Test must complete in 30 seconds
Application Code and Test Code must obey
Sandbox restrictions
Need to invoke Tests via HTTP
![Page 21: Testing Your Application On Google App Engine](https://reader031.fdocuments.us/reader031/viewer/2022030308/58f36fb11a28abcb0f8b457b/html5/thumbnails/21.jpg)
21
Conclusions
Local RunTime Environment very helpful
during Development Phase
Google Cloud Cover can be a good aid in
certain areas but need more refinement
![Page 22: Testing Your Application On Google App Engine](https://reader031.fdocuments.us/reader031/viewer/2022030308/58f36fb11a28abcb0f8b457b/html5/thumbnails/22.jpg)
22
www.inphina.comhttp://thoughts.inphina.com
![Page 23: Testing Your Application On Google App Engine](https://reader031.fdocuments.us/reader031/viewer/2022030308/58f36fb11a28abcb0f8b457b/html5/thumbnails/23.jpg)
23
References http://code.google.com/appengine/docs/java/tools/localunittesting.html
http://code.google.com/p/cloudcover/
http://thoughts.inphina.com/2010/06/28/unit-testing-maven-based-jpa-application-on-gae/
http://objectuser.wordpress.com/category/software-development/google-app-engine/
http://code.google.com/events/io/2010/sessions.html#App%20Engine