d o m a i n s p e c i f i c t e s t i n g t o o l s l e s
play

D o m a i n - S p e c i f i c T e s t i n g T - PowerPoint PPT Presentation

D o ma i n - S p e c i f i c T e s t i n g T o o l s D o m a i n - S p e c i f i c T e s t i n g T o o l s L e s s o n s l e a r n e d f r o m t h e A p a c h e S l i


  1. D o ma i n - S p e c i f i c T e s t i n g T o o l s D o m a i n - S p e c i f i c T e s t i n g T o o l s L e s s o n s l e a r n e d f r o m t h e A p a c h e S l i n g P r o j e c t R o b e r t M u n t e a n u A p a c h e C o n C o r e E u r o p e 2 0 1 5 h t t p : / / r o b e r t . mu n t e a . n u @r o mb e r t

  2. W h o I a m  $  F D A Y J O B O S S  A  A d o b e E x p e r i e n c e p a c h e S l i n g M a n a g e r  M a n t i s B T  A  M p a c h e S l i n g y l y n C o n n e c t o r f o r M a n t i s B T  A p a c h e J a c k r a b b i t  M  A y l y n C o n n e c t o r f o r R e v i e w p a c h e F e l i x B o a r d Speaker.currentSpeaker().interrupt(); h t t p : / / r o b e r t . mu n t e a . n u @r o mb e r t

  3. A g e n d a  T e s t i n g t o o l s i n g e n e r a l  B u i l d i n g d o m a i n - s p e c i f i c t e s t i n g t o o l s  D o m a i n - s p e c i f i c - t o o l s b u i l t b y A p a c h e S l i n g h t t p : / / r o b e r t . mu n t e a . n u @r o mb e r t

  4. H o w d o I t e s t my a p p l i c a t i o n ? Testing and testing tools h t t p : / / r o b e r t . mu n t e a . n u @r o mb e r t

  5. U n i t t e s t i n g @Test public void isNull() { assertThat( StringUtils.isNull( null ), is(true)); } h t t p : / / r o b e r t . mu n t e a . n u @r o mb e r t

  6. U n i t t e s t i n g w i t h mo c k s @Test public void persist() { MyDao dao = mock(MyDao.class); MyService service = new MyService(dao); service.persist(new ServiceObject()); // must not fail } h t t p : / / r o b e r t . mu n t e a . n u @r o mb e r t

  7. U n i t t e s t i n g w i t h mo c k s @Test(expected=ServiceException.class) public void persist() { MyDao dao = mock(MyDao.class); MyService service = new MyService(dao); when(dao.persist(anyObject)).thenThrow(new DaoUnavailableException("mocked")); service.persist(new ServiceObject()); } h t t p : / / r o b e r t . mu n t e a . n u @r o mb e r t

  8. I n t e g r a t i o n t e s t i n g @Test public void persist() { MyDao dao = new MyRealDao(/* config */); MyService service = new MyService(dao); service.persist(newServiceObject()); // must not fail } h t t p : / / r o b e r t . mu n t e a . n u @r o mb e r t

  9. I n t e g r a t i o n t e s t i n g - c l e a n s l a t e @Before public void ensureCleanSlate() { MyDao dao = new MyRealDao(/* config */); dao.deleteAll(); } h t t p : / / r o b e r t . mu n t e a . n u @r o mb e r t

  10. E n d - t o - e n d t e s t i n g @Test public void login() { Client client = new MyBrowserBasedClient(); AuthResult result = client.login("admin", "admin"); assertThat(result.isLoggedIn(), is(true)); } h t t p : / / r o b e r t . mu n t e a . n u @r o mb e r t

  11. T e s t i n g p y r a mi d h t t p : / / r o b e r t . mu n t e a . n u @r o mb e r t

  12. T e s t i n g p y r a mi d h t t p : / / r o b e r t . mu n t e a . n u @r o mb e r t

  13. Opinionated testing tools? h t t p : / / r o b e r t . mu n t e a . n u @r o mb e r t

  14. T e s t i n g t o o l s g a l o r e h t t p : / / r o b e r t . mu n t e a . n u @r o mb e r t

  15. Sling's Domain h t t p : / / r o b e r t . mu n t e a . n u @r o mb e r t

  16. O S G i ● P r o v i s i o n a n d d e p l o y b u n d l e s ● C o n f i g u r e , r e g i s t e r a n d l o o k u p s e r v i c e s ● E v e n t i n g ● W e b C o n s o l e h t t p : / / r o b e r t . mu n t e a . n u @r o mb e r t

  17. U n i t t e s t i n g O S G i w i t h S l i n g M o c k s public class ExampleTest { @Rule public final OsgiContext context = new OsgiContext(); @Test public void testSomething() { // register and activate service MyService service1 = context.registerInjectActivateService(new MyService(), ImmutableMap.<String, Object>of("prop1", "value1")); // get service instance OtherService service2 = context.getService(OtherService.class); } } h t t p : / / r o b e r t . mu n t e a . n u @r o mb e r t

  18. U n i t t e s t i n g O S G i w i t h t h e H u mb l e O b j e c t P a t t e r n public interface RouterAdmin { void doStuff(); } public class RouterAdminImpl implements RouterAdmin { // constructor and field elided public void doStuff() { // implementation } } @Component @Properties({ @Property(name="url") }) public class RouterAdminComponent implements RouterAdmin { private RouterAdmin delegate; protected void activate(ComponentContext ctx) throws Exception { delegate = new RouterAdminImpl(new URL(requireString(ctx, "url"))); } public void doStuff() { delegate.doStuff(); } } h t t p : / / r o b e r t . mu n t e a . n u @r o mb e r t

  19. I n t e g r a t i o n t e s t i n g O S G i w i t h P a x - E x a m public static Option[] paxConfig() { final File thisProjectsBundle = new File(System.getProperty( "bundle.file.name", "BUNDLE_FILE_NOT_SET" )); final String launchpadVersion = System.getProperty("sling.launchpad.version", "LAUNCHPAD_VERSION_NOT_SET"); log.info("Sling launchpad version: {}", launchpadVersion); return new DefaultCompositeOption( SlingPaxOptions.defaultLaunchpadOptions(launchpadVersion), CoreOptions.provision(CoreOptions.bundle(thisProjectsBundle.toU RI().toString())) ).getOptions(); } h t t p : / / r o b e r t . mu n t e a . n u @r o mb e r t

  20. I n t e g r a t i o n t e s t i n g O S G i w i t h P a x - E x a m @RunWith(PaxExam.class) public class FileNameExtractorImplIT { @Inject private FileNameExtractor fileNameExtractor; @Test public void testFileNameExtractor(){ String rawPath = "http://midches.com/images/uploads/default/demo.jpg#anchor? query=test"; String expectedFileName = "demo.jpg"; assertEquals(expectedFileName, fileNameExtractor.extract(rawPath)); } @Configuration public Option[] config() { return U.paxConfig(); } } h t t p : / / r o b e r t . mu n t e a . n u @r o mb e r t

  21. J C R h t t p : / / r o b e r t . mu n t e a . n u @r o mb e r t

  22. J C R blog hello-world jcr:content images some-cat.jpg other-cat.jpg h t t p : / / r o b e r t . mu n t e a . n u @r o mb e r t

  23. J C R - jcr:primaryType = app:asset - jcr:title = Some Cat - jcr:description = A longer description of this picture of a cat - jcr:created = 2014-06-03T00:00:00.000+02:00 - jcr:lastUpdated = 2014-06-03T11:00:00.000+02:00 - tags = [Animal, Cat, Color] - width = 400 - height = 600 h t t p : / / r o b e r t . mu n t e a . n u @r o mb e r t

  24. U n i t t e s t i n g J C R c o d e public class FindResourcesTest { @Rule public SlingContext context = new SlingContext(ResourceResolverType.JCR_MOCK); @Before public void setUp() { Resource resource = context.create().resource("test", ImmutableMap.<String, Object> builder().put("prop1", "value1") .put("prop2", "value2").build()); // snip ... MockJcr.setQueryResult(session, Collections.singletonList(node)); } @Test public void testFindResources() { Resource resource = context.resourceResolver().getResource("/test"); Assert.assertNotNull("Resource with name 'test' should be there", resource); Iterator<Resource> result = context.resourceResolver().findResources("/test", Query.XPATH); Assert.assertTrue("At least one result expected", result.hasNext()); Assert.assertEquals("/test", result.next().getPath()); Assert.assertFalse("At most one result expected", result.hasNext()); } } h t t p : / / r o b e r t . mu n t e a . n u @r o mb e r t

  25. B e t t e r u n i t t e s t i n g w i t h H a mc r e s t ma t c h e r s @Test public void loadResources() { Map<String, Object> expectedProperties = /* define properties */; Resource resource = /* load resource */ null; assertThat(resource, resourceOfType("my/app")); assertThat(resource, hasChildren("header", "body")); assertThat(resource, resourceWithProps(expectedProperties)); } h t t p : / / r o b e r t . mu n t e a . n u @r o mb e r t

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend