SlideShare a Scribd company logo
1 of 44
Testing Javascript ,[object Object]
Do you want... ,[object Object],[object Object],[object Object]
Are those your itches for Web Development? Text Every good work of software starts by scratching a developer’s personal itch. -- The Cathedral and the Bazaar by Eric S. Raymond
My itches of JavaScript ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Today’s Story ,[object Object],[object Object],[object Object]
Rhino?
Rhino is ,[object Object],http://www.mozilla.org/rhino/
Rhino now ,[object Object]
Rhino can ,[object Object],ScriptEngineManager mgr = new ScriptEngineManager(); ScriptEngine jsEngine = mgr.getEngineByName("JavaScript"); try { jsEngine.eval("print('Hello, world!')"); } catch (ScriptException ex) { ex.printStackTrace(); }
Rhino can ,[object Object],importPackage(javax.swing);  var optionPane = JOptionPane.showMessageDialog(null, 'Hello, world!');
Rhino can  ,[object Object],[object Object]
already feeling impatient? ,[object Object],An  Ant  based Javascript testing framework RhinoUnit  is run from an ANT scriptdef task using the  Rhino  engine - and uses all the helpful things that ANT provides for that.
What RhinoUnit can do ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
A general example /**   * Number.times function. 3.times(function(item){...})   *    * @param handler function   * @returns {Array}   */ Number.prototype.times = function(handler) { var results = new Array(); if (this > 0 && this == parseInt(this)) { for ( var i = 0; i < Math.ceil(this); i++) { results.push(handler(i)); } } else { throw &quot;Illegal number for times() function. Positive integer is required.&quot;; } return results; }; we have a simple function like this
A general example eval(loadFile(&quot;src/com/ciphor/ruby/Number.js&quot;)); var testNumber; testCases(test, function setUp(){ testNumber = 12; }, function testNumberTimes(){ var aNumber = new Number(10); var temp = 0; var result = aNumber.times(function(item){ temp++; return aNumber*item; }); assert.that(temp, eq(10)); assert.that(result, isCollectionContainingOnly(0,10,20,30,40,50,60,70,80,90)); } ); Test code goes like this
Our Ant build.xml ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],I am sure you know how to do the next
familiar with this? run-unit-tests : [ rhinounit ] Testsuite: TestCore.js [ rhinounit ] *** Empty TestCase, unavailable for OOAD module. *** [ rhinounit ] Tests run: 1, Failures: 0, Errors: 0 [ rhinounit ] Testsuite: TestEve.js [ rhinounit ] Tests run: 4, Failures: 0, Errors: 0 [ rhinounit ] Testsuite: TestReflection.js [ rhinounit ] Tests run: 5, Failures: 0, Errors: 0 [ rhinounit ] Testsuite: TestRubyArray.js [ rhinounit ] Tests run: 26, Failures: 0, Errors: 0 [ rhinounit ] Testsuite: TestRubyNumber.js [ rhinounit ] Tests run: 3, Failures: 0, Errors: 0 [ rhinounit ] Testsuite: TestRubyOO.js [ rhinounit ] Tests run: 7, Failures: 0, Errors: 0 [ rhinounit ] Testsuite: TestRubyString.js [ rhinounit ] Tests run: 12, Failures: 0, Errors: 0 BUILD SUCCESSFUL Total time: 922 milliseconds
want to see more? assert.that(actual, predicate) assert.mustCall(onThisObject, thisMethod) assert.mustCallNTimes(onThisObject, numberOfTimes, thisMethod) assert.functionThatMustBeCalled(thisMethod, originalFunction) assert.functionThatMustBeCalledNTimes(thisMethod, numberOfTimes, originalFunction) assert.mustNotCall(onThisObject, thisMethod) assert.functionThatMustNotBeCalled(thisMethod) assert.fail(message) assert.callStack(optionalIgnoreAfterMatching) eq(expected) similar(expected) matches(regExp) isTrue(message) isFalse(message) not(predicate) hasConstructor(expected) isA(expected) isOfType(expected) isCollectionContaining(value, value, value...) isCollectionContainingOnly(value, value, value...) containsInOrder(value, value, value...) isNull(message) eqFloat(expected, accuracy) shouldThrowException(theTest, message, checkException) Assert Object Test Functions http://code.google.com/p/rhinounit/ Test Functions
Continuous Integration ,[object Object],[object Object],[object Object],[object Object]
Jenkins jenkins-ci.org Jenkins Jenkins
Jenkins ,[object Object],[object Object],[object Object],[object Object],[object Object]
How I use it ,[object Object],[object Object],[object Object],[object Object],Interested  in Git?
Let Jenkins working with github ,[object Object],[object Object]
Let Jenkins working with github ,[object Object]
Let Jenkins working with github ,[object Object]
Let Jenkins working with github ,[object Object],[object Object]
Let Jenkins working with github ,[object Object],[object Object],$ git config user.name “your.name” $ git config user.email “your.name@email.com”
Hooray!
10:24:59  Started by user anonymous 10:24:59  Checkout:workspace / /var/lib/jenkins/jobs/CiphorJS/workspace - hudson.remoting.LocalChannel@1077aa7 10:24:59  Using strategy: Default 10:24:59  Last Built Revision: Revision 711a1c557c248b5e45364d3aafd8a4c98031f8a1 (local/master) 10:24:59  Checkout:workspace / /var/lib/jenkins/jobs/CiphorJS/workspace - hudson.remoting.LocalChannel@1077aa7 10:24:59  GitAPI created 10:24:59  Fetching changes from the remote Git repository 10:24:59  Fetching upstream changes from /home/lei.kang/workspaces/java/CiphorJS/.git 10:24:59  [workspace] $ git fetch -t /home/lei.kang/workspaces/java/CiphorJS/.git +refs/heads/*:refs/remotes/local/* 10:25:00  [workspace] $ git ls-tree HEAD 10:25:00  Fetching upstream changes from git@github.com:kangleay/CiphorJS.git 10:25:00  [workspace] $ git fetch -t git@github.com:kangleay/CiphorJS.git +refs/heads/*:refs/remotes/origin/* 10:25:13  [workspace] $ git ls-tree HEAD 10:25:13  Seen branch in repository local/master 10:25:13  Seen branch in repository origin/master 10:25:13  Commencing build of Revision 711a1c557c248b5e45364d3aafd8a4c98031f8a1 (local/master) 10:25:13  GitAPI created 10:25:13  Checking out Revision 711a1c557c248b5e45364d3aafd8a4c98031f8a1 (local/master) 10:25:13  [workspace] $ git checkout -f 711a1c557c248b5e45364d3aafd8a4c98031f8a1 10:25:13  [workspace] $ git tag -a -f -m &quot;Hudson Build #37&quot; hudson-CiphorJS-37 10:25:13  Recording changes in branch local/master 10:25:14  [workspace] $ git whatchanged --no-abbrev -M –pretty=raw 711a1c557c248b5e45364d3aafd8a4c98031f8a1..711a1c557c248b5e45364d3aafd8a4c98031f8a1 What is it doing behind?
What is it doing behind? 10:25:14  [workspace] $ ant -file build.xml run-unit-tests 10:25:14  Buildfile: build.xml 10:25:15  10:25:15  run-unit-tests: 10:25:15  [rhinounit] Testsuite: TestCore.js 10:25:15  [rhinounit] *** Empty TestCase, unavailable for OOAD module. *** 10:25:15  [rhinounit] Tests run: 1, Failures: 0, Errors: 0 10:25:15  [rhinounit]  10:25:15  [rhinounit] Testsuite: TestEve.js 10:25:15  [rhinounit] Tests run: 4, Failures: 0, Errors: 0 10:25:15  [rhinounit]  10:25:15  [rhinounit] Testsuite: TestReflection.js 10:25:15  [rhinounit] Tests run: 5, Failures: 0, Errors: 0 10:25:15  [rhinounit]  10:25:15  [rhinounit] Testsuite: TestRubyArray.js 10:25:15  [rhinounit] Tests run: 26, Failures: 0, Errors: 0 10:25:15  [rhinounit]  10:25:15  [rhinounit] Testsuite: TestRubyNumber.js 10:25:15  [rhinounit] Tests run: 3, Failures: 0, Errors: 0 10:25:15  [rhinounit]  10:25:15  [rhinounit] Testsuite: TestRubyOO.js 10:25:15  [rhinounit] Tests run: 7, Failures: 0, Errors: 0 10:25:15  [rhinounit]  10:25:15  [rhinounit] Testsuite: TestRubyString.js 10:25:15  [rhinounit] Tests run: 12, Failures: 0, Errors: 0 10:25:15  [rhinounit]  10:25:15  10:25:15  BUILD SUCCESSFUL 10:25:15  Total time: 0 seconds 10:25:15  GitAPI created 10:25:15  [workspace] $ git tag -d hudson-CiphorJS-37 10:25:15  [workspace] $ git tag -a -f -m &quot;Hudson Build #37&quot; hudson-CiphorJS-37-SUCCESS 10:25:15  GitAPI created 10:25:15  Pushing HEAD to branch master at repo origin 10:25:15  [workspace] $ git push git@github.com:kangleay/CiphorJS.git HEAD:master 10:25:20  Finished: SUCCESS
What have I done? Commit Git Local  Repository Detected by Build and Test Jenkins  workspace Git Remote  Repository (GitHub) Publish Success As an open source project, people now can check out source from github and enjoy!
Extremely bored? Should I continue?
Automated Web UI Testing ,[object Object],[object Object],[object Object]
iMacros Just DRY Don't Repeat Yourself
iMacros Works for both IE and Firefox
iMacros Let's do it Actions speak louder than words.
Web Testing
Web Testing
Web Testing
Web Testing
Web Testing
OK, That's the whole story today,  Thank you!
Reference Rhino  http://www.mozilla.org/rhino/ RhinoUnit  http://code.google.com/p/rhinounit/ Jenkins  http://jenkins-ci.org/ iMacros  https://addons.mozilla.org/en-us/firefox/addon/imacros-for-firefox/ CiphorJS  http://www.ciphor.com/wiki/index.php/CiphorJS
Coming soon... ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

More Related Content

What's hot

Shift Remote: Mobile - Devops-ify your life with Github Actions - Nicola Cort...
Shift Remote: Mobile - Devops-ify your life with Github Actions - Nicola Cort...Shift Remote: Mobile - Devops-ify your life with Github Actions - Nicola Cort...
Shift Remote: Mobile - Devops-ify your life with Github Actions - Nicola Cort...Shift Conference
 
Analyzing FreeCAD's Source Code and Its "Sick" Dependencies
Analyzing FreeCAD's Source Code and Its "Sick" DependenciesAnalyzing FreeCAD's Source Code and Its "Sick" Dependencies
Analyzing FreeCAD's Source Code and Its "Sick" DependenciesPVS-Studio
 
JavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good PartsJavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good PartsKonrad Malawski
 
Puppet at GitHub - PuppetConf 2013
Puppet at GitHub - PuppetConf 2013Puppet at GitHub - PuppetConf 2013
Puppet at GitHub - PuppetConf 2013Puppet
 
Adventures in infrastructure as code
Adventures in infrastructure as codeAdventures in infrastructure as code
Adventures in infrastructure as codeJulian Simpson
 
Going native with less coupling: Dependency Injection in C++
Going native with less coupling: Dependency Injection in C++Going native with less coupling: Dependency Injection in C++
Going native with less coupling: Dependency Injection in C++Daniele Pallastrelli
 
One commit, one release. Continuously delivering a Symfony project.
One commit, one release. Continuously delivering a Symfony project.One commit, one release. Continuously delivering a Symfony project.
One commit, one release. Continuously delivering a Symfony project.Javier López
 
Java Boilerplate Busters
Java Boilerplate BustersJava Boilerplate Busters
Java Boilerplate BustersHamletDRC
 
Continous Delivering a PHP application
Continous Delivering a PHP applicationContinous Delivering a PHP application
Continous Delivering a PHP applicationJavier López
 
Reactive programming with tracker
Reactive programming with trackerReactive programming with tracker
Reactive programming with trackerDesignveloper
 
Going On with the Check of Geant4
Going On with the Check of Geant4Going On with the Check of Geant4
Going On with the Check of Geant4Andrey Karpov
 
GitGot: The Swiss Army Chainsaw of Git Repo Management
GitGot: The Swiss Army Chainsaw of Git Repo ManagementGitGot: The Swiss Army Chainsaw of Git Repo Management
GitGot: The Swiss Army Chainsaw of Git Repo ManagementJohn Anderson
 
Androidの本当にあった怖い話
Androidの本当にあった怖い話Androidの本当にあった怖い話
Androidの本当にあった怖い話Yusuke Yamamoto
 
Test or Go Fishing - a guide on how to write better Swift for iOS
Test or Go Fishing - a guide on how to write better Swift for iOSTest or Go Fishing - a guide on how to write better Swift for iOS
Test or Go Fishing - a guide on how to write better Swift for iOSPaul Ardeleanu
 
Dependency Injection with CDI in 15 minutes
Dependency Injection with CDI in 15 minutesDependency Injection with CDI in 15 minutes
Dependency Injection with CDI in 15 minutesAntonio Goncalves
 
Grails Plugin
Grails PluginGrails Plugin
Grails Pluginguligala
 
PgTAP Best Practices
PgTAP Best PracticesPgTAP Best Practices
PgTAP Best PracticesDavid Wheeler
 

What's hot (20)

Shift Remote: Mobile - Devops-ify your life with Github Actions - Nicola Cort...
Shift Remote: Mobile - Devops-ify your life with Github Actions - Nicola Cort...Shift Remote: Mobile - Devops-ify your life with Github Actions - Nicola Cort...
Shift Remote: Mobile - Devops-ify your life with Github Actions - Nicola Cort...
 
Analyzing FreeCAD's Source Code and Its "Sick" Dependencies
Analyzing FreeCAD's Source Code and Its "Sick" DependenciesAnalyzing FreeCAD's Source Code and Its "Sick" Dependencies
Analyzing FreeCAD's Source Code and Its "Sick" Dependencies
 
JavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good PartsJavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good Parts
 
Puppet at GitHub - PuppetConf 2013
Puppet at GitHub - PuppetConf 2013Puppet at GitHub - PuppetConf 2013
Puppet at GitHub - PuppetConf 2013
 
CDI: How do I ?
CDI: How do I ?CDI: How do I ?
CDI: How do I ?
 
Adventures in infrastructure as code
Adventures in infrastructure as codeAdventures in infrastructure as code
Adventures in infrastructure as code
 
GvaScript Library
GvaScript LibraryGvaScript Library
GvaScript Library
 
Going native with less coupling: Dependency Injection in C++
Going native with less coupling: Dependency Injection in C++Going native with less coupling: Dependency Injection in C++
Going native with less coupling: Dependency Injection in C++
 
One commit, one release. Continuously delivering a Symfony project.
One commit, one release. Continuously delivering a Symfony project.One commit, one release. Continuously delivering a Symfony project.
One commit, one release. Continuously delivering a Symfony project.
 
Java Boilerplate Busters
Java Boilerplate BustersJava Boilerplate Busters
Java Boilerplate Busters
 
Continous Delivering a PHP application
Continous Delivering a PHP applicationContinous Delivering a PHP application
Continous Delivering a PHP application
 
Reactive programming with tracker
Reactive programming with trackerReactive programming with tracker
Reactive programming with tracker
 
Going On with the Check of Geant4
Going On with the Check of Geant4Going On with the Check of Geant4
Going On with the Check of Geant4
 
Zenly - Reverse geocoding
Zenly - Reverse geocodingZenly - Reverse geocoding
Zenly - Reverse geocoding
 
GitGot: The Swiss Army Chainsaw of Git Repo Management
GitGot: The Swiss Army Chainsaw of Git Repo ManagementGitGot: The Swiss Army Chainsaw of Git Repo Management
GitGot: The Swiss Army Chainsaw of Git Repo Management
 
Androidの本当にあった怖い話
Androidの本当にあった怖い話Androidの本当にあった怖い話
Androidの本当にあった怖い話
 
Test or Go Fishing - a guide on how to write better Swift for iOS
Test or Go Fishing - a guide on how to write better Swift for iOSTest or Go Fishing - a guide on how to write better Swift for iOS
Test or Go Fishing - a guide on how to write better Swift for iOS
 
Dependency Injection with CDI in 15 minutes
Dependency Injection with CDI in 15 minutesDependency Injection with CDI in 15 minutes
Dependency Injection with CDI in 15 minutes
 
Grails Plugin
Grails PluginGrails Plugin
Grails Plugin
 
PgTAP Best Practices
PgTAP Best PracticesPgTAP Best Practices
PgTAP Best Practices
 

Similar to Testing of javacript

SF JUG - GWT Can Help You Create Amazing Apps - 2009-10-13
SF JUG - GWT Can Help You Create Amazing Apps - 2009-10-13SF JUG - GWT Can Help You Create Amazing Apps - 2009-10-13
SF JUG - GWT Can Help You Create Amazing Apps - 2009-10-13Fred Sauer
 
把鐵路開進視窗裡
把鐵路開進視窗裡把鐵路開進視窗裡
把鐵路開進視窗裡Wei Jen Lu
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven DevelopmentPapp Laszlo
 
Scripting Oracle Develop 2007
Scripting Oracle Develop 2007Scripting Oracle Develop 2007
Scripting Oracle Develop 2007Tugdual Grall
 
Front End Development for Back End Developers - UberConf 2017
Front End Development for Back End Developers - UberConf 2017Front End Development for Back End Developers - UberConf 2017
Front End Development for Back End Developers - UberConf 2017Matt Raible
 
RichFaces - Testing on Mobile Devices
RichFaces - Testing on Mobile DevicesRichFaces - Testing on Mobile Devices
RichFaces - Testing on Mobile DevicesPavol Pitoňák
 
Release with confidence
Release with confidenceRelease with confidence
Release with confidenceJohn Congdon
 
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years laterSymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years laterHaehnchen
 
Building native Android applications with Mirah and Pindah
Building native Android applications with Mirah and PindahBuilding native Android applications with Mirah and Pindah
Building native Android applications with Mirah and PindahNick Plante
 
Javascript unit testing, yes we can e big
Javascript unit testing, yes we can   e bigJavascript unit testing, yes we can   e big
Javascript unit testing, yes we can e bigAndy Peterson
 
Building Web Apps Sanely - EclipseCon 2010
Building Web Apps Sanely - EclipseCon 2010Building Web Apps Sanely - EclipseCon 2010
Building Web Apps Sanely - EclipseCon 2010Chris Ramsdale
 
Fullstack workshop
Fullstack workshopFullstack workshop
Fullstack workshopAssaf Gannon
 
Gitlab and Lingvokot
Gitlab and LingvokotGitlab and Lingvokot
Gitlab and LingvokotLingvokot
 
DevOps(4) : Ansible(2) - (MOSG)
DevOps(4) : Ansible(2) - (MOSG)DevOps(4) : Ansible(2) - (MOSG)
DevOps(4) : Ansible(2) - (MOSG)Soshi Nemoto
 
Using Git as your VCS with Bioconductor
Using Git as your VCS with BioconductorUsing Git as your VCS with Bioconductor
Using Git as your VCS with Bioconductortimyates
 
PyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web ApplicationsPyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web ApplicationsGraham Dumpleton
 

Similar to Testing of javacript (20)

SF JUG - GWT Can Help You Create Amazing Apps - 2009-10-13
SF JUG - GWT Can Help You Create Amazing Apps - 2009-10-13SF JUG - GWT Can Help You Create Amazing Apps - 2009-10-13
SF JUG - GWT Can Help You Create Amazing Apps - 2009-10-13
 
把鐵路開進視窗裡
把鐵路開進視窗裡把鐵路開進視窗裡
把鐵路開進視窗裡
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Scripting Oracle Develop 2007
Scripting Oracle Develop 2007Scripting Oracle Develop 2007
Scripting Oracle Develop 2007
 
Front End Development for Back End Developers - UberConf 2017
Front End Development for Back End Developers - UberConf 2017Front End Development for Back End Developers - UberConf 2017
Front End Development for Back End Developers - UberConf 2017
 
RichFaces - Testing on Mobile Devices
RichFaces - Testing on Mobile DevicesRichFaces - Testing on Mobile Devices
RichFaces - Testing on Mobile Devices
 
Release with confidence
Release with confidenceRelease with confidence
Release with confidence
 
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years laterSymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
 
GWT Extreme!
GWT Extreme!GWT Extreme!
GWT Extreme!
 
Building native Android applications with Mirah and Pindah
Building native Android applications with Mirah and PindahBuilding native Android applications with Mirah and Pindah
Building native Android applications with Mirah and Pindah
 
Guides To Analyzing WebKit Performance
Guides To Analyzing WebKit PerformanceGuides To Analyzing WebKit Performance
Guides To Analyzing WebKit Performance
 
Javascript unit testing, yes we can e big
Javascript unit testing, yes we can   e bigJavascript unit testing, yes we can   e big
Javascript unit testing, yes we can e big
 
Building Web Apps Sanely - EclipseCon 2010
Building Web Apps Sanely - EclipseCon 2010Building Web Apps Sanely - EclipseCon 2010
Building Web Apps Sanely - EclipseCon 2010
 
Fullstack workshop
Fullstack workshopFullstack workshop
Fullstack workshop
 
Griffon Presentation
Griffon PresentationGriffon Presentation
Griffon Presentation
 
Gitlab and Lingvokot
Gitlab and LingvokotGitlab and Lingvokot
Gitlab and Lingvokot
 
DevOps(4) : Ansible(2) - (MOSG)
DevOps(4) : Ansible(2) - (MOSG)DevOps(4) : Ansible(2) - (MOSG)
DevOps(4) : Ansible(2) - (MOSG)
 
Why Gradle?
Why Gradle?Why Gradle?
Why Gradle?
 
Using Git as your VCS with Bioconductor
Using Git as your VCS with BioconductorUsing Git as your VCS with Bioconductor
Using Git as your VCS with Bioconductor
 
PyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web ApplicationsPyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web Applications
 

Testing of javacript

  • 1.
  • 2.
  • 3. Are those your itches for Web Development? Text Every good work of software starts by scratching a developer’s personal itch. -- The Cathedral and the Bazaar by Eric S. Raymond
  • 4.
  • 5.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14. A general example /** * Number.times function. 3.times(function(item){...}) * * @param handler function * @returns {Array} */ Number.prototype.times = function(handler) { var results = new Array(); if (this > 0 && this == parseInt(this)) { for ( var i = 0; i < Math.ceil(this); i++) { results.push(handler(i)); } } else { throw &quot;Illegal number for times() function. Positive integer is required.&quot;; } return results; }; we have a simple function like this
  • 15. A general example eval(loadFile(&quot;src/com/ciphor/ruby/Number.js&quot;)); var testNumber; testCases(test, function setUp(){ testNumber = 12; }, function testNumberTimes(){ var aNumber = new Number(10); var temp = 0; var result = aNumber.times(function(item){ temp++; return aNumber*item; }); assert.that(temp, eq(10)); assert.that(result, isCollectionContainingOnly(0,10,20,30,40,50,60,70,80,90)); } ); Test code goes like this
  • 16.
  • 17. familiar with this? run-unit-tests : [ rhinounit ] Testsuite: TestCore.js [ rhinounit ] *** Empty TestCase, unavailable for OOAD module. *** [ rhinounit ] Tests run: 1, Failures: 0, Errors: 0 [ rhinounit ] Testsuite: TestEve.js [ rhinounit ] Tests run: 4, Failures: 0, Errors: 0 [ rhinounit ] Testsuite: TestReflection.js [ rhinounit ] Tests run: 5, Failures: 0, Errors: 0 [ rhinounit ] Testsuite: TestRubyArray.js [ rhinounit ] Tests run: 26, Failures: 0, Errors: 0 [ rhinounit ] Testsuite: TestRubyNumber.js [ rhinounit ] Tests run: 3, Failures: 0, Errors: 0 [ rhinounit ] Testsuite: TestRubyOO.js [ rhinounit ] Tests run: 7, Failures: 0, Errors: 0 [ rhinounit ] Testsuite: TestRubyString.js [ rhinounit ] Tests run: 12, Failures: 0, Errors: 0 BUILD SUCCESSFUL Total time: 922 milliseconds
  • 18. want to see more? assert.that(actual, predicate) assert.mustCall(onThisObject, thisMethod) assert.mustCallNTimes(onThisObject, numberOfTimes, thisMethod) assert.functionThatMustBeCalled(thisMethod, originalFunction) assert.functionThatMustBeCalledNTimes(thisMethod, numberOfTimes, originalFunction) assert.mustNotCall(onThisObject, thisMethod) assert.functionThatMustNotBeCalled(thisMethod) assert.fail(message) assert.callStack(optionalIgnoreAfterMatching) eq(expected) similar(expected) matches(regExp) isTrue(message) isFalse(message) not(predicate) hasConstructor(expected) isA(expected) isOfType(expected) isCollectionContaining(value, value, value...) isCollectionContainingOnly(value, value, value...) containsInOrder(value, value, value...) isNull(message) eqFloat(expected, accuracy) shouldThrowException(theTest, message, checkException) Assert Object Test Functions http://code.google.com/p/rhinounit/ Test Functions
  • 19.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 29. 10:24:59 Started by user anonymous 10:24:59 Checkout:workspace / /var/lib/jenkins/jobs/CiphorJS/workspace - hudson.remoting.LocalChannel@1077aa7 10:24:59 Using strategy: Default 10:24:59 Last Built Revision: Revision 711a1c557c248b5e45364d3aafd8a4c98031f8a1 (local/master) 10:24:59 Checkout:workspace / /var/lib/jenkins/jobs/CiphorJS/workspace - hudson.remoting.LocalChannel@1077aa7 10:24:59 GitAPI created 10:24:59 Fetching changes from the remote Git repository 10:24:59 Fetching upstream changes from /home/lei.kang/workspaces/java/CiphorJS/.git 10:24:59 [workspace] $ git fetch -t /home/lei.kang/workspaces/java/CiphorJS/.git +refs/heads/*:refs/remotes/local/* 10:25:00 [workspace] $ git ls-tree HEAD 10:25:00 Fetching upstream changes from git@github.com:kangleay/CiphorJS.git 10:25:00 [workspace] $ git fetch -t git@github.com:kangleay/CiphorJS.git +refs/heads/*:refs/remotes/origin/* 10:25:13 [workspace] $ git ls-tree HEAD 10:25:13 Seen branch in repository local/master 10:25:13 Seen branch in repository origin/master 10:25:13 Commencing build of Revision 711a1c557c248b5e45364d3aafd8a4c98031f8a1 (local/master) 10:25:13 GitAPI created 10:25:13 Checking out Revision 711a1c557c248b5e45364d3aafd8a4c98031f8a1 (local/master) 10:25:13 [workspace] $ git checkout -f 711a1c557c248b5e45364d3aafd8a4c98031f8a1 10:25:13 [workspace] $ git tag -a -f -m &quot;Hudson Build #37&quot; hudson-CiphorJS-37 10:25:13 Recording changes in branch local/master 10:25:14 [workspace] $ git whatchanged --no-abbrev -M –pretty=raw 711a1c557c248b5e45364d3aafd8a4c98031f8a1..711a1c557c248b5e45364d3aafd8a4c98031f8a1 What is it doing behind?
  • 30. What is it doing behind? 10:25:14 [workspace] $ ant -file build.xml run-unit-tests 10:25:14 Buildfile: build.xml 10:25:15 10:25:15 run-unit-tests: 10:25:15 [rhinounit] Testsuite: TestCore.js 10:25:15 [rhinounit] *** Empty TestCase, unavailable for OOAD module. *** 10:25:15 [rhinounit] Tests run: 1, Failures: 0, Errors: 0 10:25:15 [rhinounit] 10:25:15 [rhinounit] Testsuite: TestEve.js 10:25:15 [rhinounit] Tests run: 4, Failures: 0, Errors: 0 10:25:15 [rhinounit] 10:25:15 [rhinounit] Testsuite: TestReflection.js 10:25:15 [rhinounit] Tests run: 5, Failures: 0, Errors: 0 10:25:15 [rhinounit] 10:25:15 [rhinounit] Testsuite: TestRubyArray.js 10:25:15 [rhinounit] Tests run: 26, Failures: 0, Errors: 0 10:25:15 [rhinounit] 10:25:15 [rhinounit] Testsuite: TestRubyNumber.js 10:25:15 [rhinounit] Tests run: 3, Failures: 0, Errors: 0 10:25:15 [rhinounit] 10:25:15 [rhinounit] Testsuite: TestRubyOO.js 10:25:15 [rhinounit] Tests run: 7, Failures: 0, Errors: 0 10:25:15 [rhinounit] 10:25:15 [rhinounit] Testsuite: TestRubyString.js 10:25:15 [rhinounit] Tests run: 12, Failures: 0, Errors: 0 10:25:15 [rhinounit] 10:25:15 10:25:15 BUILD SUCCESSFUL 10:25:15 Total time: 0 seconds 10:25:15 GitAPI created 10:25:15 [workspace] $ git tag -d hudson-CiphorJS-37 10:25:15 [workspace] $ git tag -a -f -m &quot;Hudson Build #37&quot; hudson-CiphorJS-37-SUCCESS 10:25:15 GitAPI created 10:25:15 Pushing HEAD to branch master at repo origin 10:25:15 [workspace] $ git push git@github.com:kangleay/CiphorJS.git HEAD:master 10:25:20 Finished: SUCCESS
  • 31. What have I done? Commit Git Local Repository Detected by Build and Test Jenkins workspace Git Remote Repository (GitHub) Publish Success As an open source project, people now can check out source from github and enjoy!
  • 32. Extremely bored? Should I continue?
  • 33.
  • 34. iMacros Just DRY Don't Repeat Yourself
  • 35. iMacros Works for both IE and Firefox
  • 36. iMacros Let's do it Actions speak louder than words.
  • 42. OK, That's the whole story today, Thank you!
  • 43. Reference Rhino http://www.mozilla.org/rhino/ RhinoUnit http://code.google.com/p/rhinounit/ Jenkins http://jenkins-ci.org/ iMacros https://addons.mozilla.org/en-us/firefox/addon/imacros-for-firefox/ CiphorJS http://www.ciphor.com/wiki/index.php/CiphorJS
  • 44.