O slideshow foi denunciado.
Seu SlideShare está sendo baixado. ×

Unit Testing XQuery on MarkLogic

Ad

declare function testFeature() {
  let $actual := feature:doFeature()
  (: assert feature condition :)
};




declare func...

Ad

declare function doFeature() {
  let $output := lotsOfLogic()
  return $output
};

Ad

declare namespace its = “http://www.w3.org/2005/11/its”;

declare function buildXmlWithTranslateFlags() {
  element data {...

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Ad

Próximos SlideShares
Metadata-driven Testing
Metadata-driven Testing
Carregando em…3
×

Confira estes a seguir

1 de 90 Anúncio
1 de 90 Anúncio

Unit Testing XQuery on MarkLogic

Baixar para ler offline

Unit testing is a required part of a healthy software development lifecycle. Business logic in MarkLogic Xquery needs the same insurance of superb testing as any other language.

Principles: Come learn the motivation for unit testing and how test-driven development can increase your productivity writing solid Xquery code in an Agile-coding environment.

Skills: We'll code Xquery examples to learn general skills including the TDD workflow, how to isolate your code for unit testability, and how to test one thing at a time. In each case, we'll address how to apply these skills specifically to development in the MarkLogic environment.

Tools: We'll also introduce you to in-house-developed tooling for creating unit tests and running them. This tooling provides an all-Xquery method of creating test functions, annotating them as such so they're runnable in the test runner, isolating certain modules to test, and viewing clear test results.

With a few principles, skills, and tools for unit testing, you can go forward with increased confidence that the Xquery code you write on MarkLogic is more awesome than ever.

This slide deck is from a presentation at the MarkLogic Users Conference 2011.

More info available at RockyCode.com

Unit testing is a required part of a healthy software development lifecycle. Business logic in MarkLogic Xquery needs the same insurance of superb testing as any other language.

Principles: Come learn the motivation for unit testing and how test-driven development can increase your productivity writing solid Xquery code in an Agile-coding environment.

Skills: We'll code Xquery examples to learn general skills including the TDD workflow, how to isolate your code for unit testability, and how to test one thing at a time. In each case, we'll address how to apply these skills specifically to development in the MarkLogic environment.

Tools: We'll also introduce you to in-house-developed tooling for creating unit tests and running them. This tooling provides an all-Xquery method of creating test functions, annotating them as such so they're runnable in the test runner, isolating certain modules to test, and viewing clear test results.

With a few principles, skills, and tools for unit testing, you can go forward with increased confidence that the Xquery code you write on MarkLogic is more awesome than ever.

This slide deck is from a presentation at the MarkLogic Users Conference 2011.

More info available at RockyCode.com

Mais Conteúdo rRelacionado

Unit Testing XQuery on MarkLogic

  1. 1. declare function testFeature() { let $actual := feature:doFeature() (: assert feature condition :) }; declare function doFeature() { () (: todo: impl :) };
  2. 2. declare function doFeature() { let $output := lotsOfLogic() return $output };
  3. 3. declare namespace its = “http://www.w3.org/2005/11/its”; declare function buildXmlWithTranslateFlags() { element data { attribute its:translate { “yes” }, businessLogicToBuildXml(); } };
  4. 4. declare function buildXml() { element data { businessLogicToBuildXml(); } }; declare namespace its = “http://www.w3.org/2005/11/its”; declare function addTranslateFlags($xml) { element {$xml/fn:name()} { attribute its:translate { “yes” }, $xml/@*, $xml/* } };
  5. 5. import module namespace build = “b” at “/build.xqy”; declare function testBuildXml() { let $actual := b:buildXml() (: assert only xml is well-built :) }; import module namespace translate = “t” at “/transl8.xqy”; declare function testAddTranslateFlags() { let $actual := t:addTranslateFlags() (: assert only that translation flags added correctly :) };
  6. 6. import module namespace build = “b” at “/build.xqy”; declare function buildXml_condition1() { (: ... :) }; declare function buildXml_condition2() { (: ... :) }; (: etc. :)
  7. 7. declare function bizLogic($input as element()*) { (: ... :) }; import module namespace logic = “logic” at “/logic.xqy”; declare function bizLogic_emptyInput() { (: ... :) }; declare function bizLogic_oneInput() { (: ... :) }; declare function bizLogic_manyInput() { (: ... :) };
  8. 8. declare function bizLogic($input as element()*) { (: ... :) }; import module namespace logic = “logic” at “/logic.xqy”; declare function bizLogic_insufficientInput() { (: ... :) }; declare function bizLogic_malformedInput() { (: ... :) };
  9. 9. declare function bizLogic($input as element()*) { if (isInsufficientInput($input)) then fn:error(xs:Qname(“ASSERT”), “Insufficient msg”) else (: normal process... :) }; import module namespace logic = “logic” at “/logic.xqy”; declare function bizLogic_insufficientInput() { try { (: call w/ insufficient input :) } catch ($e) { if ($e/error:name eq “ASSERT”) then () else xdmp:rethrow() } };
  10. 10. declare function businessLogic($input) { let $moreInput := /more-input[@attr eq $input] let $returnVal := for $item in $moreInput let $details := /detail[@id eq $item/id] return if ($details/thing eq xdmp:get-request-field(“thing-id”)) then $details else () return if (fn:exists($returnVal)) then let $audit := xdmp:document-insert(“/latest.xml”, element ok {}) return $returnVal else xdmp:redirect-response(“/empty.xqy”); };
  11. 11. declare function businessLogic($input) { let $moreInput := /more-input[@attr eq $input] let $returnVal := for $item in $moreInput let $details := /detail[@id eq $item/id] return if ($details/thing eq xdmp:get-request-field(“thing-id”)) then $details else () return if (fn:exists($returnVal)) then let $audit := xdmp:document-insert(“/latest.xml”, element ok {}) return $returnVal else xdmp:redirect-response(“/empty.xqy”); };
  12. 12. xdmp:get-request-field(“var”) xdmp:redirect-response(“/page.xqy”)
  13. 13. fn:collection()/dances/rain xdmp:document-insert(“/trades.xml”, element beads {})
  14. 14. declare function feature() { let $filter := xdmp:get-request-field(“filter”) let $input := fn:collection()/data[@attr eq $filter] let $result := businessLogic($input) let $persist := xdmp:document-insert(“/doc.xml”, $result) return xdmp:redirect-response(“complete.xqy”) };
  15. 15. declare function feature() { let $filter := xdmp:get-request-field(“filter”) let $input := fn:collection()/data[@attr eq $filter] let $result := businessLogic($input) let $persist := xdmp:document-insert(“/doc.xml”, $result) return xdmp:redirect-response(“complete.xqy”) };
  16. 16. declare function (:TEST:) isolate_noUrlNoChannels() { (: ... :) };
  17. 17. <dependency> <groupId>org.lds.marklogic.shared</groupId> <artifactId>xqtest</artifactId> <version>1.0-SNAPSHOT</version> <type>xar</type> </dependency>
  18. 18. import module namespace unit = "http://lds.org/code/shared/xqtest/html" at "/shared/xqtest/html.xqy"; html:test()
  19. 19. import module namespace unit = "http://lds.org/code/shared/xqtest/testng" at "/shared/xqtest/testng.xqy"; testng:test()
  20. 20. <channels> <channel> <name>Dress &amp; Grooming</name> <path>/dress-grooming/</path> <channels> <!-- ... --> <channels> </channel> <!-- ... --> </channels>
  21. 21. ... test - show only active subchannels - green test - show only active subchannels - red test - 1 child level all children - green test - 1 child level, 2 exist - green test - 1 child level, 2 exist - red test - 1 child level - green test - child level - red test - get closest url - green test - get closest url - red test - match level 2 - green test - match level 2 - red test - active chg - match whole tree & match lvl1 partial tree - green test - active chg - match whole tree & match lvl1 partial tree - red test - match lvl1 partial tree - red test - match whole tree - green test - match whole tree – red ...
  22. 22. Demo'able parameters style adjustment added stylesheet for sidebar added demo page, adjusted reverse tree builder to handle queried docs testng runner added xqtest ver .5 - update to work with new api test - limit shallow non-hierarchical url - green test - shallow limit 1 level, 2 exist - green test - adjust test (only work with hierarchical urls) - shallow … test - shallow limit 1 level, 2 exist - red test - deep limit 1 level, 2 exist - green test - adjust test - deep limit 1 level, 2 exist - red test - limit 1 level, 2 exist - red test - level 3 active link - green test - level 3 active link - red test - level 3 list none active (and fixed level 2 test data) - green test - level 3 list none active - red cleanup - privatize fn's test - level 2 list none active - green test - level 2 list none active - red test - header only multiple level 1 channel - green test - header only multiple level 1 channel - red test - header only - green test - header only - red test - no channels data - green test - no channels data - red test - no channels - green added sidebar renderer - no channels test - red renamed build->render fn added build fn test - build max child levels of set to more - green test - no match 3 levels, 2 exist, 2 shown (fixed bug) - green test - no match 3 levels, 2 exist, 2 shown - red test - no match level 1, 2 exist - fix - green test - no match level 1, 2 exist - green test - no match levels more than exists - green test - no match level 1 - green test - no match level 1 - red cleanup long fn signatures test - show only active subchannels - green test - show only active subchannels - red test - 1 child level all children - green test - 1 child level, 2 exist - green test - 1 child level, 2 exist - red test - 1 child level - green test - child level - red test - get closest url - green test - get closest url - red test - match level 2 - green test - match level 2 - red test - active chg - match whole tree & match lvl1 partial tree - green test - active chg - match whole tree & match lvl1 partial tree - red test - match lvl1 partial tree - red test - match whole tree - green test - match whole tree - red Rename isolateChannels -> isolate Rename nav -> channel Rename nav2 -> nav Added gitignore Initial import - base test cases (no input)
  23. 23. Demo'able parameters style adjustment added stylesheet for sidebar added demo page, adjusted reverse tree builder to handle queried docs testng runner added xqtest ver .5 - update to work with new api test - limit shallow non-hierarchical url - green test - shallow limit 1 level, 2 exist - green test - adjust test (only work with hierarchical urls) - shallow … test - shallow limit 1 level, 2 exist - red test - deep limit 1 level, 2 exist - green test - adjust test - deep limit 1 level, 2 exist - red test - limit 1 level, 2 exist - red test - level 3 active link - green test - level 3 active link - red test - level 3 list none active (and fixed level 2 test data) - green test - level 3 list none active - red cleanup - privatize fn's test - level 2 list none active - green test - level 2 list none active - red test - header only multiple level 1 channel - green test - header only multiple level 1 channel - red test - header only - green test - header only - red test - no channels data - green test - no channels data - red test - no channels - green added sidebar renderer - no channels test - red renamed build->render fn added build fn test - build max child levels of set to more - green test - no match 3 levels, 2 exist, 2 shown (fixed bug) - green test - no match 3 levels, 2 exist, 2 shown - red test - no match level 1, 2 exist - fix - green test - no match level 1, 2 exist - green test - no match levels more than exists - green test - no match level 1 - green test - no match level 1 - red cleanup long fn signatures test - show only active subchannels - green test - show only active subchannels - red test - 1 child level all children - green test - 1 child level, 2 exist - green test - 1 child level, 2 exist - red test - 1 child level - green test - child level - red test - get closest url - green test - get closest url - red test - match level 2 - green test - match level 2 - red test - active chg - match whole tree & match lvl1 partial tree - green test - active chg - match whole tree & match lvl1 partial tree - red test - match lvl1 partial tree - red test - match whole tree - green test - match whole tree - red Rename isolateChannels -> isolate Rename nav -> channel Rename nav2 -> nav Added gitignore Initial import - base test cases (no input)
  24. 24. Al l Cre a t ive Co m mons 2.0 At t ribution Li ce n se un l e ss o t herwise n o ted Green Apple (modified) Hugging Fingers Decoupled http://www.flickr.com/photos/_fxr/2335186114/ http://www.flickr.com/photos/ganesha_isis/4439563089/ http://www.flickr.com/photos/daquellamanera/2213902727/ _FXR's photostream ganesha.isis' photostream Daquella manera's photostream Salt Lake Temple Fail Whale Water Droplet http://www.flickr.com/photos/midiman/2503776540/ http://www.flickr.com/photos/coletivomambembe/3882172324/ http://www.flickr.com/photos/shannonkringen/4680455907/ midiman's photostream Coletivo Mambembe's photostream shannonkringen's photostream Belay Lego Death Star http://www.flickr.com/photos/picsbycam/5173647461/ http://www.flickr.com/photos/dudeoflego/5104751355/ Cameron Cassan's photostream Dude of Lego's photostream Thinker Road Runner http://www.flickr.com/photos/garysoup/2705102139/ http://www.flickr.com/photos/snowpeak/4815685925/ Gary Soup's photostream snowpeak's photostream Multipurpose Tool Keyboard Sleep http://www.flickr.com/photos/paalb/11772559/ http://www.flickr.com/photos/ytruly/1718468702/ Pål Berge's photostream YTruly's photostream Clean Up Lotus http://www.flickr.com/photos/emilyrides/5188289325/lightbox/ http://www.flickr.com/photos/thecarspy/2571799871/in/photostream/ emilydickinsonridesabmx's photostream The Car Spy's photostream Cliff Neon Pipes http://www.flickr.com/photos/elsie/144702426/ http://www.flickr.com/photos/krossbow/3619931451/ Elsie esq.'s photostream krossbow's photostream - CC Attribution license Paper Pile Calculator http://www.flickr.com/photos/loty/326761635/ http://www.flickr.com/photos/scoobay/2463236523/ lotyloty's photostream Scoobay's photostream Candles Dragon Boat http://www.flickr.com/photos/picsbycam/4023646774/in/photostream/ http://www.flickr.com/photos/wiifm69/3410782558/ Cameron Cassan's photostream wiifm's photostream Elephant Ping Pong http://www.flickr.com/photos/greenboots76/2924276160/ http://www.flickr.com/photos/ncc_badiey/4932760753/ Henry Brett's photostream Nima Badiey's photostream Assembly Line Solitary Confinement http://www.flickr.com/photos/jurvetson/5201796697/ http://www.flickr.com/photos/59195512@N00/143521274/ jurvetson's photostream dospaz's photostream Chihuahua Flags http://www.flickr.com/photos/62337512@N00/3727104807/ http://www.flickr.com/photos/markchapmanphoto/5138832677/ apdk's photostream ::: Radar Communication :::'s photostream Angry Dog Pointing Caterpillar http://www.flickr.com/photos/javiercito/2083111412/lightbox/ http://www.flickr.com/photos/pinkstockphotos/5266977224/ Javiercit0's photostream PinkStock Photos!'s photostream Clean up Pet Multiplication http://www.flickr.com/photos/pointshoot/1144799868/ http://www.flickr.com/photos/somegeekintn/4048155967/ Eddie~S' photostream somegeekintn's photostream
  25. 25. Pig Egg Safety Net Mexican Hat Rock Formation http://www.flickr.com/photos/katerha/5423107783/ http://www.flickr.com/photos/iamchadhearmesnore/3629410556/ http://www.flickr.com/photos/wolfgangstaudt/4879456199/in/set- katerha's photostream iamchad's photostream 72157624891093384 Wolfgang Staudt's photostream Spaghetti Noodle Black Box http://www.flickr.com/photos/pinksherbet/2201247567/ http://www.flickr.com/photos/amagill/34762677/ Red Apple (modified) Pink Sherbet Photography's photostream AMagill's photostream http://www.flickr.com/photos/emzee/273289101/ *Micky's photostream Girl Eating Spaghetti Tool Belt http://www.flickr.com/photos/pinksherbet/5008273559/ http://www.flickr.com/photos/blue_diamond/3995257652/ Kodak Roll Pink Sherbet Photography's photostream Blue Diamond Photography's photostream http://www.flickr.com/photos/picsbycam/4550970565/in/photostream/ Cameron Cassan's photostream Salute Flag The Swede http://www.flickr.com/photos/soldiersmediacenter/3920702814/ By David Quinn, used with permission Gnuolane Free font The U.S. Army's photostream http://typodermicfonts.com Garden Gnome Free for personal and commercial use Camoflauge Lizard http://www.flickr.com/photos/mukluk/196177233/ http://www.flickr.com/photos/lofink/4453281926/ Dano's photostream dlofink's photostream Blueprint Call on Beach http://www.flickr.com/photos/wscullin/3770016707/ http://www.flickr.com/photos/zitona/2268296925/ Will Scullin's photostream » Zitona «'s photostream Flux Capacitor Indian Chief http://www.flickr.com/photos/popculturegeek/4533455371/ http://www.flickr.com/photos/boston_public_library/4100786887/in/photo popculturegeek.com's photostream stream/ Boston Public Library's photostream Power Plug http://www.flickr.com/photos/randomurl/438112948/ Ninja Turtle Zevotron's photostream http://www.flickr.com/photos/86805724@N00/1581833575/ ianmalcm's photostream Runner http://www.flickr.com/photos/lululemonathletica/5197327623/lightbox/ Phone Booth lululemon athletica's photostream http://www.flickr.com/photos/bexwalton/4204409348/ Bex.Walton's photostream Yoga Man http://www.flickr.com/photos/lululemonathletica/4774517755/ Suit lululemon athletica's photostream http://www.flickr.com/photos/pss/4830803189/ Paul Stevenson's photostream Lego City Men http://www.flickr.com/photos/mac_filko/5491561002/ Underwater mac_filko's photostream http://www.flickr.com/photos/andreweick/4000567498/in/photostream/ AndrewEick's photostream Port Said http://www.flickr.com/photos/48722974@N07/5036484008/ Picasso eutrophication&hypoxia's photostream http://www.flickr.com/photos/oddsock/101164507/ oddsock's photostream Vote for Pedro http://www.flickr.com/photos/emdot/79863648/ Spider Tunnel emdot's photostream http://www.flickr.com/photos/b1gw1ght/900924265/ b1gw1ght's photostream Dusty Road http://www.flickr.com/photos/generated/5554654197/ jared's photostream

×