More Related Content Similar to Testing of javacript (20) Testing of javacript3. 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 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 "Illegal number for times() function. Positive integer is required."; } return results; }; we have a simple function like this 15. A general example eval(loadFile("src/com/ciphor/ruby/Number.js")); 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 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 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 "Hudson Build #37" 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 "Hudson Build #37" 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! 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