Test. Unit. Runner
Test.
0001:new Test.Unit.Runner({
0002: setup: function() {},
0003: teardown: function () {},
0004: testAssertEqual: function() { with(this) {
0005: assertEqual(0, 0);
0006:
0007: assertEqual(0,'0');
0008: assertEqual(65.0, 65);
0009:
0010: assertEqual("a", "a");
0011:
0012: assertNotEqual(0, 1);
0013: assertNotEqual("a","b");
0014: }}
0015:})
それではコードに戻りましょう。
0138:Test.Unit.Runner = Class.create();
0139:Test.Unit.Runner.prototype = {
0140: initialize: function(testcases) {
0141: this.options = Object.extend({
0142: testLog: 'testlog'
0143: }, arguments[1] || {});
0144: this.options.resultsURL = this.parseResultsURLQueryParameter();
0145: this.options.tests = this.parseTestsQueryParameter();
0146: if (this.options.testLog) {
0147: this.options.testLog = $(this.options.testLog) || null;
0148: }
0149: if(this.options.tests) {
0150: this.tests = [];
0151: for(var i = 0; i < this.options.tests.length; i++) {
0152: if(/^test/.test(this.options.tests[i])) {
0153: this.tests.push(new Test.Unit.Testcase(this.options.tests[i], testcases[this.options.tests[i]], testcases["setup"], testcases["teardown"]));
0154: }
0155: }
0156: } else {
0157: if (this.options.test) {
0158: this.tests = [new Test.Unit.Testcase(this.options.test, testcases[this.options.test], testcases["setup"], testcases["teardown"])];
0159: } else {
0160: this.tests = [];
0161: for(var testcase in testcases) {
0162: if(/^test/.test(testcase)) {
0163: this.tests.push(
0164: new Test.Unit.Testcase(
0165: this.options.context ? ' -> ' + this.options.titles[testcase] : testcase,
0166: testcases[testcase], testcases["setup"], testcases["teardown"]
0167: ));
0168: }
0169: }
0170: }
0171: }
0172: this.currentTest = 0;
0173: this.logger = new Test.Unit.Logger(this.options.testLog);
0174: setTimeout(this.runTests.bind(this), 1000);
0175: },
140~175行目のinitializeは,
以下のオプションがあります。
- testLog
- 結果を出力する要素のDOM idです。デフォルトは'testlog'です。
- resultsURL
- クエリパラメータresultsURLから与えます。結果の送信先のURLです。
- tests
- クエリパラメータtestsから与えます。引数で与えたtestcasesの中から,
実行したいテスト名をカンマ区切りで指定します。 - test
- 引数で与えたtestcasesの中から,
実行したいテスト名を1つ指定します。 - context
- 有効にすると,
次のtitlesのオプションが使われます。 - titles
- テストのそれぞれにタイトルをつけることができます。キーにテスト名,
値にタイトルのハッシュテーブルを与えます。
144行目で,
145行目で,
146行目で,
149~156行目で,
157行目で,
159~170行目で,
172行目で,
173行目で,
174行目で,
0176: parseResultsURLQueryParameter: function() {
0177: return window.location.search.parseQuery()["resultsURL"];
0178: },
176~178行目のparseResultsURLQueryParameterは,
0179: parseTestsQueryParameter: function(){
0180: if (window.location.search.parseQuery()["tests"]){
0181: return window.location.search.parseQuery()["tests"].split(',');
0182: };
0183: },
179~183行目のparseTestsQueryParameterは,