<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    qileilove

    blog已經(jīng)轉(zhuǎn)移至github,大家請(qǐng)?jiān)L問 http://qaseven.github.io/

    QUnit單元測(cè)試文檔

    QUnit.test( "hello test", function ( assert ) {
    assert.ok( 1 == "1", "Passed!" );
    } )
      //綜述
    var test = [
    "QUnit.asyncTest()",//Add an asynchronous test to run. The test must include a call to QUnit.start().
    "QUnit.module()", //Group related tests under a single label. 一個(gè)標(biāo)簽下的組相關(guān)測(cè)試
    "QUnit.test()" //Add a test to run.
    ],
    assertProperties = [
    "deepEqual",//深度遞歸比較,基本類型,數(shù)組、對(duì)象、正則表達(dá)式、日期和功能
    "notDeepEqual",
    "equal",
    "notEqual",
    "strictEqual",//嚴(yán)格比較 值和類型
    "strictEqual",
    "propEqual",//用于嚴(yán)格對(duì)比對(duì)象 包括對(duì)象的值、屬性的數(shù)據(jù)類型 (類似== 和===的差別)
    "notPropEqual",
    "expect",//期望(數(shù)量)注冊(cè)一個(gè)預(yù)期的計(jì)數(shù)。如果斷言運(yùn)行的數(shù)量不匹配預(yù)期的統(tǒng)計(jì),測(cè)試就會(huì)失敗。
    "ok",// 一個(gè)布爾檢查
    "push",//輸出封裝的JavaScript函數(shù)返回的結(jié)果報(bào)告
    "throws"http://測(cè)試如果一個(gè)回調(diào)函數(shù)拋出一個(gè)異常,并有選擇地比較拋出的錯(cuò)誤。
    ],
    asyncControl = [
    "asyncTest", // QUnit測(cè)試異步代碼。asyncTest將自動(dòng)停止測(cè)試運(yùn)行器,等待您的代碼調(diào)用QUnit.start()繼續(xù)。
    "start", //Start running tests again after the testrunner was stopped
    "stop"  //當(dāng)異步測(cè)試有多個(gè)出口點(diǎn),使用QUnit.stop 增加解除test runner等待 應(yīng)該調(diào)用QUnit.start()的次數(shù)。
    ],
    callbackHandlers = [
    "begin",
    "done",
    "log",
    "moduleStart",
    "moduleDone",
    "testStart",
    "testDone"
    ],
    Configuration = [
    "assert",
    "config",
    "QUnit.dump.parse()",
    "QUnit.extend() "
    ];
     //region test
    QUnit.test( "a test", function ( assert ) {
    function square( x ) {
    return x * x;
    }
    var result = square( 2 );
    assert.equal( result, 4, "square(2) equals 4" );
    } );
    QUnit.asyncTest( "asynchronous test: one second later!", function ( assert ) {
    assert.expect( 1 );
    setTimeout( function () {
    assert.ok( true, "Passed and ready to resume!" );
    QUnit.start();
    }, 1000 );
    } );
    //endregion
      //region assert 斷言
    //deepEqual   對(duì)應(yīng)notDeepEqual() 深度遞歸比較,基本類型,數(shù)組、對(duì)象、正則表達(dá)式、日期和功能
    QUnit.test( "deepEqual test", function ( assert ) {
    var obj = { foo : "bar" };
    assert.deepEqual( obj, { foo : "bar" }, "Two objects can be the same in value" );
    } );
    QUnit.test( "notDeepEqual test", function ( assert ) {
    var obj = { foo : "bar" };
    assert.notDeepEqual( obj, { foo : "bla" }, "Different object, same key, different value, not equal" );
    } );
    //equal 對(duì)應(yīng)notEqual()
    QUnit.test( "a test", function ( assert ) {
    assert.equal( 1, "1", "String '1' and number 1 have the same value" );
    assert.equal( 0, 0, "Zero, Zero; equal succeeds" );
    assert.equal( "", 0, "Empty, Zero; equal succeeds" );
    assert.equal( "", "", "Empty, Empty; equal succeeds" );
    assert.equal( "three", 3, "Three, 3; equal fails" );
    assert.equal( null, false, "null, false; equal fails" );
    } );
    QUnit.test( "a test", function ( assert ) {
    assert.notEqual( 1, "2", "String '2' and number 1 don't have the same value" );
    } );
    //strictEqual()  notStrictEqual()
    QUnit.test( "strictEqual test", function ( assert ) {
    assert.strictEqual( 1, 1, "1 and 1 have the same value and type" );
    } );
    QUnit.test( "a test", function ( assert ) {
    assert.notStrictEqual( 1, "1", "String '1' and number 1 have the same value but not the same type" );
    } );
    //propEqual notPropEqual 用于嚴(yán)格對(duì)比對(duì)象 包括對(duì)象的值、屬性的數(shù)據(jù)類型 (equal和propEqual 類似== 和===的差別)
    QUnit.test( "notPropEqual test", function ( assert ) {
    function Foo( x, y, z ) {
    this.x = x;
    this.y = y;
    this.z = z;
    }
    Foo.prototype.doA = function () {
    };
    Foo.prototype.doB = function () {
    };
    Foo.prototype.bar = 'prototype';
    var foo = new Foo( 1, "2", [] );
    var bar = new Foo( "1", 2, {} );
    assert.notPropEqual( foo, bar, "Properties values are strictly compared." );
    } );
    //expect 期望(數(shù)量)注冊(cè)一個(gè)預(yù)期的計(jì)數(shù)。如果斷言運(yùn)行的數(shù)量不匹配預(yù)期的統(tǒng)計(jì),測(cè)試就會(huì)失敗。
    QUnit.test( "a test", function ( assert ) {
    assert.expect( 3 );
    function calc( x, operation ) {
    return operation( x );
    }
    var result = calc( 2, function ( x ) {
    assert.ok( true, "calc() calls operation function" );
    return x * x;
    } );
    assert.equal( result, 4, "2 squared equals 4" );
    } );
    //ok  一個(gè)布爾檢查
    QUnit.test( "ok test", function ( assert ) {
    assert.ok( true, "true succeeds" );
    assert.ok( "non-empty", "non-empty string succeeds" );
    assert.ok( false, "false fails" );
    assert.ok( 0, "0 fails" );
    assert.ok( NaN, "NaN fails" );
    assert.ok( "", "empty string fails" );
    assert.ok( null, "null fails" );
    assert.ok( undefined, "undefined fails" );
    } );
    //push() 輸出封裝的JavaScript函數(shù)返回的結(jié)果報(bào)告
    //一些測(cè)試套件可能需要表達(dá)一個(gè)期望,不是由任何QUnit內(nèi)置的斷言。這種需要一個(gè)封裝的JavaScript函數(shù),該函數(shù)返回一個(gè)布爾值,表示結(jié)果,這個(gè)值可以傳遞到QUnit的斷言。
    QUnit.assert.mod2 = function ( value, expected, message ) {
    var actual = value % 2;
    this.push( actual === expected, actual, expected, message );
    };
    QUnit.test( "mod2", function ( assert ) {
    assert.expect( 2 );
    assert.mod2( 2, 0, "2 % 2 == 0" );
    assert.mod2( 3, 1, "3 % 2 == 1" );
    } );
    //測(cè)試如果一個(gè)回調(diào)函數(shù)拋出一個(gè)異常,并有選擇地比較拋出的錯(cuò)誤。
    QUnit.test( "throws", function ( assert ) {
    function CustomError( message ) {
    this.message = message;
    }
    CustomError.prototype.toString = function () {
    return this.message;
    };
    assert.throws(
    function () {
    throw "error"
    },
    "throws with just a message, not using the 'expected' argument"
    );
    assert.throws(
    function () {
    throw new CustomError( "some error description" );
    },
    /description/,
    "raised error message contains 'description'"
    );
    assert.throws(
    function () {
    throw new CustomError();
    },
    CustomError,
    "raised error is an instance of CustomError"
    );
    assert.throws(
    function () {
    throw new CustomError( "some error description" );
    },
    new CustomError( "some error description" ),
    "raised error instance matches the CustomError instance"
    );
    assert.throws(
    function () {
    throw new CustomError( "some error description" );
    },
    function ( err ) {
    return err.toString() === "some error description";
    },
    "raised error instance satisfies the callback function"
    );
    } );
    //endregion
      //region async-control異步控制
    //QUnit.asyncTest() QUnit測(cè)試異步代碼。asyncTest將自動(dòng)停止測(cè)試運(yùn)行器,等待您的代碼調(diào)用QUnit.start()繼續(xù)。
    QUnit.asyncTest( "asynchronous test: one second later!", function ( assert ) {
    assert.expect( 1 );
    setTimeout( function () {
    assert.ok( true, "Passed and ready to resume!" );
    QUnit.start();
    }, 1000 );
    } );
    QUnit.asyncTest( "asynchronous test: video ready to play", function ( assert ) {
    assert.expect( 1 );
    var $video = $( "video" );
    $video.on( "canplaythrough", function () {
    assert.ok( true, "video has loaded and is ready to play" );
    QUnit.start();
    } );
    } );
    //QUnit.start() Start running tests again after the testrunner was stopped
    //QUnit.stop()  當(dāng)異步測(cè)試有多個(gè)出口點(diǎn),使用QUnit.stop 增加解除test runner等待 應(yīng)該調(diào)用QUnit.start()的次數(shù)。
    QUnit.test( "a test", function ( assert ) {
    assert.expect( 1 );
    QUnit.stop();
    setTimeout( function () {
    assert.equal( "someExpectedValue", "someExpectedValue", "ok" );
    QUnit.start();
    }, 150 );
    } );
    //endregion
      //region module QUnit.module()后發(fā)生的所有測(cè)試調(diào)用將被分到模塊,直到調(diào)用其他其他QUnit.module()。
    // 測(cè)試結(jié)果的測(cè)試名稱都將使用模塊名稱。可以使用該模塊名稱來(lái)選擇模塊內(nèi)的所有測(cè)試運(yùn)行。
    //Example: Use the QUnit.module() function to group tests together:
    QUnit.module( "group a" );
    QUnit.test( "a basic test example", function ( assert ) {
    assert.ok( true, "this test is fine" );
    } );
    QUnit.test( "a basic test example 2", function ( assert ) {
    assert.ok( true, "this test is fine" );
    } );
    QUnit.module( "group b" );
    QUnit.test( "a basic test example 3", function ( assert ) {
    assert.ok( true, "this test is fine" );
    } );
    QUnit.test( "a basic test example 4", function ( assert ) {
    assert.ok( true, "this test is fine" );
    } );
    //Example: A sample for using the setup and teardown callbacks
    QUnit.module( "module A", {
    setup : function () {
    // prepare something for all following tests
    },
    teardown : function () {
    // clean up after each test
    }
    } );
    //Example: Lifecycle properties are shared on respective test context 在測(cè)試環(huán)境下共享各自的生命周期內(nèi)的屬性
    QUnit.module( "Machine Maker", {
    setup : function () {
    },
    parts : [ "wheels", "motor", "chassis" ]
    } );
    QUnit.test( "makes a robot", function ( assert ) {
    this.parts.push( "arduino" );
    assert.equal( this.parts, "robot" );
    assert.deepEqual( this.parts, [ "robot" ] );
    } );
    QUnit.test( "makes a car", function ( assert ) {
    assert.equal( this.parts, "car" );
    assert.deepEqual( this.parts, [ "car", "car" ] );
    } );
    //endregion
      //region callback
    //begin  Register a callback to fire whenever the test suite begins.
    QUnit.begin( function ( details ) {
    console.log( "Test amount:", details.totalTests );
    } );
    //done  Register a callback to fire whenever the test suite ends.
    QUnit.done( function ( details ) {
    console.log( "Total: ", details.total, " Failed: ", details.failed, " Passed: ", details.passed, " Runtime: ", details.runtime );
    } );
    //log  Register a callback to fire whenever an assertion completes.
    QUnit.log( function ( details ) {
    if ( details.result ) {
    return;
    }
    var loc = details.module + ": " + details.name + ": ",
    output = "FAILED: " + loc + ( details.message ? details.message + ", " : "" );
    if ( details.actual ) {
    output += "expected: " + details.expected + ", actual: " + details.actual;
    }
    if ( details.source ) {
    output += ", " + details.source;
    }
    console.log( output );
    } );
    //moduleStart  Register a callback to fire whenever a module begins.
    QUnit.moduleStart( function ( details ) {
    console.log( "Now running: ", details.name );
    } );
    //moduleDone  Register a callback to fire whenever a module ends.
    QUnit.moduleDone( function ( details ) {
    console.log( "Finished running: ", details.name, "Failed/total: ", details.failed, details.total );
    } );
    //testStart Register a callback to fire whenever a test begins.
    QUnit.testStart( function ( details ) {
    console.log( "Now running: ", details.module, details.name );
    } );
    //testDone Register a callback to fire whenever a test ends.
    QUnit.testDone( function ( details ) {
    console.log( "Finished running: ", details.module, details.name, "Failed/total: ", details.failed, details.total, details.duration );
    } );
    //endregion
     //region Configuration
    //assert Namespace for QUnit assertions
    QUnit.test( "`ok` assertion defined in the callback parameter", function ( assert ) {
    assert.ok( true, "on the object passed to the `test` function" );
    } );
    //config Configuration for QUnit
    QUnit.config.autostart = false;
    QUnit.config.current.testName = "zodiac";
    QUnit.config.urlConfig.push( {
    id : "jquery",
    label : "jQuery version",
    value : [ "1.7.2", "1.8.3", "1.9.1" ],
    tooltip : "What jQuery Core version to test against"
    } );
    //QUnit.dump.parse() 它解析數(shù)據(jù)結(jié)構(gòu)和對(duì)象序列化為字符串。也解析DOM元素outerHtml為字符串
    QUnit.log( function ( obj ) {
    // Parse some stuff before sending it.
    var actual = QUnit.dump.parse( obj.actual );
    var expected = QUnit.dump.parse( obj.expected );
    // Send it.
    } );
    var qHeader = document.getElementById( "qunit-header" ),
    parsed = QUnit.dump.parse( qHeader );
    console.log( parsed );
    // Logs: "<h1 id=\"qunit-header\"></h1>"
    //QUnit.extend() Copy the properties defined by the mixin object into the target object
    QUnit.test( "QUnit.extend", function ( assert ) {
    var base = {
    a : 1,
    b : 2,
    z : 3
    };
    QUnit.extend( base, {
    b : 2.5,
    c : 3,
    z : undefined
    } );
    assert.equal( base.a, 1, "Unspecified values are not modified" );
    assert.equal( base.b, 2.5, "Existing values are updated" );
    assert.equal( base.c, 3, "New values are defined" );
    assert.ok( !( "z" in base ), "Values specified as `undefined` are removed" );
    } );
    //endregion

    posted on 2014-12-11 23:24 順其自然EVO 閱讀(156) 評(píng)論(0)  編輯  收藏 所屬分類: 測(cè)試學(xué)習(xí)專欄

    <2014年12月>
    30123456
    78910111213
    14151617181920
    21222324252627
    28293031123
    45678910

    導(dǎo)航

    統(tǒng)計(jì)

    常用鏈接

    留言簿(55)

    隨筆分類

    隨筆檔案

    文章分類

    文章檔案

    搜索

    最新評(píng)論

    閱讀排行榜

    評(píng)論排行榜

    主站蜘蛛池模板: 玖玖在线免费视频| 成人在线免费视频| 99久热只有精品视频免费观看17| 国产成人一区二区三区免费视频| 亚洲私人无码综合久久网| 一个人在线观看视频免费| 亚洲乱码一区av春药高潮| 久久国内免费视频| 精品亚洲456在线播放| 最近最好的中文字幕2019免费 | 久久香蕉国产线看观看亚洲片| 在线视频网址免费播放| 久久亚洲国产成人精品无码区| 一级成人毛片免费观看| 中文字幕亚洲无线码| 久久精品一区二区免费看| 九月丁香婷婷亚洲综合色| 国产好大好硬好爽免费不卡| 亚洲视屏在线观看| 免费高清在线爱做视频| 羞羞视频免费网站入口| 亚洲日本一区二区三区在线| 午夜免费福利片观看| 国产精品亚洲专区在线观看 | 中美日韩在线网免费毛片视频| 亚洲日本一区二区一本一道| 成人国产精品免费视频| 亚洲91精品麻豆国产系列在线| 131美女爱做免费毛片| 亚洲а∨天堂久久精品9966| 亚洲Av无码乱码在线观看性色| 久久不见久久见免费影院www日本| 亚洲免费观看视频| a毛片基地免费全部视频| 男男gay做爽爽免费视频| 亚洲国产精品VA在线观看麻豆 | 久久精品国产精品亚洲下载| 免费人成毛片动漫在线播放| 亚洲免费在线视频观看| 午夜亚洲福利在线老司机| 国产一区二区三区在线免费|