• Like

Loading…

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

YUI Test The Next Generation (YUIConf 2010)

  • 5,859 views
Uploaded on

JavaScript testing has grown by leaps and bounds over the past few years. When YUI Test was first introduced in 2007, it was just the first step in a long process of bringing test-driven development …

JavaScript testing has grown by leaps and bounds over the past few years. When YUI Test was first introduced in 2007, it was just the first step in a long process of bringing test-driven development to the front end. YUI Test evolved with the release of YUI 3 to introduce mock objects as feedback indicated a need. As feedback continued to come in, YUI Test continued to evolve. Learn about the next version of YUI Test, how it makes testing any JavaScript code easier, and the brand new tools that allow you to integrate your testing into a continuous integration environment.

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
5,859
On Slideshare
0
From Embeds
0
Number of Embeds
3

Actions

Shares
Downloads
87
Comments
0
Likes
6

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Nicholas C. Zakas YUIConf Yahoo!, Inc. November 9, 2010
  • 2. Who's this guy? @captain_picard @slicknet
  • 3. Who's this guy? Principal Front End Contributor, Engineer Creator of YUI Test Author Lead Author Contributor Lead Author
  • 4. YUI Test How'd we get here?
  • 5. Mock Objects YUI Test Debut Friendly Test Names July 2007 (YUI 2.3.0) September 2009 (YUI 3.0.0) Automation Hooks Test-Driven Development JUnit XML and TAP Formats with YUI Test (Talk) April 2010 (YUI 3.1.0) October 2008 Writing effective tests ZOMG!!! (YUIBlog) Today January 2009 Getting started with Yeti Released YUI Test (YUIBlog) August 2010 December 2008 Async Testing Automated Integration Testing TestReporter with YUI Test (Talk) XML and JSON Test Formats October 2009 December 2007 (YUI 2.4.0)
  • 6. Today YUI Test YUI Test YUI Test Standalone Library Selenium Driver Coverage
  • 7. Today YUI Test YUI Test YUI Test Standalone Library Selenium Driver Coverage
  • 8. YUI Test Standalone Library has no YUI dependencies You can load it completely on its own – outside of YUI 2.x and YUI 3.x
  • 9. Why? To address a series of ongoing problems
  • 10. Problem Inconsistencies across versions
  • 11. YUI Test for YUI 2.x YAHOO.tool.TestCase YAHOO.tool.TestSuite YAHOO.tool.TestRunner YAHOO.tool.TestReporter YAHOO.tool.TestManager YAHOO.tool.TestFormat YAHOO.util.Assert YAHOO.util.ArrayAssert YAHOO.util.DateAssert YAHOO.util.ObjectAssert
  • 12. YUI Test for YUI 3.x Y.Test.Case Y.Test.Suite Y.Test.Runner Y.Test.Reporter Y.Test.Format Y.Assert Y.ArrayAssert Y.DateAssert Y.ObjectAssert Y.Mock
  • 13. Hmmmm... YAHOO.tool.TestCase Y.Test.Case YAHOO.tool.TestSuite Y.Test.Suite YAHOO.tool.TestRunner Y.Test.Runner YAHOO.tool.TestReporter Y.Test.Reporter YAHOO.tool.TestManager YAHOO.tool.TestFormat Y.Test.Format YAHOO.util.Assert Y.Assert YAHOO.util.ArrayAssert Y.ArrayAssert YAHOO.util.DateAssert Y.DateAssert YAHOO.util.ObjectAssert Y.ObjectAssert Y.Mock
  • 14. YUI Test Standalone 1.0.0 YUITest.TestCase YUITest.TestSuite YUITest.TestRunner YUITest.Reporter YUITest.PageManager YUITest.TestFormat YUITest.Assert YUITest.ArrayAssert YUITest.DateAssert YUITest.ObjectAssert YUITest.Mock
  • 15. Problem I'd like to use YUI Test, but not YUI
  • 16. Problem Everyone else is doing it
  • 17. What's it look like?
  • 18. <script type="text/javascript" src="yuitest.js"></script> <script type="text/javascript"> var testCase = new YUITest.TestCase({ name: "Same ol' test case", testSomething: function(){ YUITest.Assert.isTrue(true); }, "This should work": function(){ YUITest.Assert.isTrue(works); } }); Familiar Syntax! YUITest.TestRunner.add(testCase); YUITest.TestRunner.run(); </script>
  • 19. var testSuite = new YUITest.TestSuite("name"); testSuite.add(testCase1); testSuite.add(testCase2); YUITest.TestRunner.add(testSuite); YUITest.TestRunner.run(); Familiar Syntax!
  • 20. Not just a port! API cleanup & bug fixes
  • 21. YUITest.ObjectAssert areEqual() hasKey() hasKeys() ownsKey() ownsKeys() ownsNoKeys() inheritsKey() inheritsKeys() ownsOrInheritsKey() ownsOrInheritsKeys()
  • 22. Friendlier Test Names var testCase = new YUITest.TestCase({ name: "My Test Case", "This should be a test": function(){ //this is a test in YUI Test for YUI 3.x }, "As is this one": function(){ //this is not a test in YUI Test for YUI 3.x //but is in YUI Test Standalone 1.0.0 } });
  • 23. Counting Asserts var testCase = new YUITest.TestCase({ name: "My Test Case", "This should be a test": function(){ //this test passes in YUI Test for YUI 3.x //but fails in YUI Test Standalone 1.0.0 } });
  • 24. Beyond _should var testCase = new YUITest.TestCase({ name: "My Test Case", _should: { //old "Another test": "Error message" }, "Another test": function(){ //new someFunction(); } });
  • 25. Beyond _should var testCase = new YUITest.TestCase({ name: "My Test Case", "Another test": function(){ //new YUITest.Assert.throwsError("Error message", someFunction); } });
  • 26. What about the YUI 2.x and 3.x versions? YUI Test Standalone becomes the core implementation of both
  • 27. Today YUI Test YUI Test YUI Test Standalone Library Selenium Driver Coverage
  • 28. Easy automation for continuous integration
  • 29. Hudson Continuous build/testing system Used to periodically build from source and validate by running tests http://hudson-ci.org/
  • 30. Hack Selenium Hudson SelNG ? JUnit TAP Screen scrape
  • 31. Hack Selenium Hudson SelNG ? JUnit TAP Screen scrape
  • 32. Selenium Web application testing system Primarily used by QA organizations for functional testing http://seleniumhq.org/
  • 33. Selenium Remote Control http://seleniumhq.org/projects/remote-control/
  • 34. Hudson ? Selenium RC Screen scraping to gather results = ick
  • 35. Hudson Selenium Selenium Driver RC
  • 36. Selenium Driver Three primary goals
  • 37. #1 Completely handle communication between Hudson and Selenium RC Yes, Uhura once wore yellow – focus, people
  • 38. #2 Extract as much data as possible from tests Return the results in a format that Hudson can consume and report on
  • 39. #3 Don't force already-existing tests to change Seriously, it's just wrong
  • 40. Test Pages var testCase = new YUITest.TestCase({ name: "My Test Case", //... }); YUITest.TestRunner.add(testCase); YUITest.TestRunner.run(); Test pages must automatically begin running tests without additional interaction
  • 41. Command Line Usage: java -jar yuitest-selenium-driver-x.y.z.jar [options] [test files] Global Options -h, --help Displays this information. --browsers <browsers> Run tests in these browsers (comma-delimited). --conf <file> Load options from <file>. --coveragedir <dir> Output coverage files to <dir>. --erroronfail Indicates that a test failure should cause an error to be reported to the console. --host <host> Use the Selenium host <host>. --port <port> Use <port> port on the Selenium host. --resultsdir <dir> Output test result files to <dir>. --silent Don't output test results to the console. --tests <file> Loads test info from <file>. -v, --verbose Display informational messages and warnings.
  • 42. Examples java -jar yuitest-selenium-driver.jar http://www.example.com/tests/test_ui java -jar yuitest-selenium-driver.jar --host selenium.example.com --port 9080 http://www.example.com/tests/test_ui java -jar yuitest-selenium-driver.jar --browsers *firefox,*iexplore http://www.example.com/tests/test_ui http://www.example.com/tests/test_util java -jar yuitest-selenium-driver.jar --tests tests.xml
  • 43. Tests File <?xml version="1.0"?> <yuitest> <tests base="http://www.example.com/tests/" timeout="10000"> <url>test_core</url> <url timeout="30000">test_util</url> <url>test_ui</url> </tests> </yuitest> Easiest way to specify multiple tests to execute on the same host machine
  • 44. Demo (Sorry Slideshare viewers)
  • 45. Today YUI Test YUI Test YUI Test Standalone Library Selenium Driver Coverage
  • 46. What is code coverage?
  • 47. I dunna know what happened, all my tests passed!
  • 48. What was it you were testing, Mr. Scott?
  • 49. ...
  • 50. Code coverage tells you what code executed during testing
  • 51. Code can have multiple paths function doSomething(){ if (condition){ doSomethingElse(); } else { doAThirdThing(); } } The goal of unit testing is to exercise each path The goal of code coverage is to identify if you did
  • 52. doSomething() condition doSomethingElse() doAThirdThing()
  • 53. doSomething() condition doSomethingElse() doAThirdThing()
  • 54. doSomething() condition doSomethingElse() doAThirdThing()
  • 55. Step One Instrument JavaScript
  • 56. file.js Coverage covered-file.js
  • 57. Command Line Usage: java -jar yuitest-coverage-x.y.z.jar [options] [file|dir] Global Options -h, --help Displays this information. --charset <charset> Read the input file using <charset>. -d, --dir Input and output (-o) are both directories. -v, --verbose Display informational messages and warnings. -o <file|dir> Place the output into <file|dir>. Defaults to stdout.
  • 58. Step Two Run tests with instrumented JavaScript
  • 59. Step Three Generate reports
  • 60. Extract Coverage Data Yourself //object results results = YUITest.TestRunner.getCoverage(); //standard JSON results format results = YUITest.TestRunner.getCoverage( YUITest.CoverageFormat.JSON); //alternate format results = YUITest.TestRunner.getCoverage( YUITest.CoverageFormat.XebugJSON);
  • 61. results.json Coverage Report Report
  • 62. Command Line Usage: java -jar yuitest-coverage-report-x.y.z.jar [options] [file] Global Options -h, --help Displays this information. --format <format> Output reports in <format>. Defaults to HTML. -v, --verbose Display informational messages and warnings. -o <file|dir> Place the output into <file|dir>.
  • 63. Selenium Coverage Driver Selenium Driver automatically pulls in coverage data
  • 64. Complete Testing Solution YUI Test YUI Test YUI Test Standalone Library Selenium Driver Coverage JavaScript continuous integration testing system
  • 65. Compatibility • YUI Test Standalone Library 1.0.0 • YUI Test for YUI 3.1.1+ • YUI Test for YUI 2.8.1+
  • 66. Contribute • GitHub: http://github.com/yui/yuitest/ • YUILibrary: http://yuilibrary.com/projects/yuitest/ • YUIBlog Announcement: http://www.yuiblog.com/blog/2010/11/09/intro ducing-the-new-yui-test
  • 67. Questions?
  • 68. Etcetera • My blog: www.nczonline.net • Twitter: @slicknet • These Slides: http://slideshare.net/nzakas/ • Rate Me: http://spkr8.com/t/4999
  • 69. Creative Commons Images Used • http://www.flickr.com/photos/anks/3311228772/ • http://www.flickr.com/photos/eschipul/4716821041/