Zombie.js和Jasmine有什么区别?

时间:2017-02-04 19:09:21

标签: jasmine zombie.js

我知道Zombie.js和Jasmine有什么区别?他们都是框架吗?

1 个答案:

答案 0 :(得分:2)

Jasmine 是BDD(行为驱动开发)的单元测试框架。它需要像NodeJs这样的执行环境或Firefox,Chrome,IE,PhantomJS等浏览器来运行(并为被测代码提供环境)。 Jasmine提供测试执行和断言基础结构(describe()it()expect())。

Zombie.js 是一个模拟的无头浏览器。它本身就是一个浏览器,还有自己的交互API。它就像Selenium / Webdriver。它使用jsdom来提供浏览器通常提供的API。 Zombie.js 需要测试执行和断言基础结构(如Mocha + should.js甚至是Jasmine)。

  • 使用Jasmine,您可以在模块或模块组级别上编写测试。但通常不在应用程序级别

  • 使用Zombie.js,您可以通过交互API与网站(由服务器提供服务)进行互动。

  • 使用Jasmine,您可以在输出上为特定输入创建精细的断言 - 在模块级别上。

  • 使用Zombie.js,您可以与整个应用程序(或网站)进行互动。

  • 使用Jasmine,您只测试Javascript部分。

  • 使用Zombie.js测试frontent +后端。虽然你可能会嘲笑和拦截服务器交互(也许,我不熟悉它)。

  • 使用Jasmine,您可以调用方法/函数,传递参数并测试返回值和事件

  • 使用Zombie.js加载页面并填写表单并测试输出

  • 使用Jasmine,您需要在正确的执行环境中运行测试(如Firefox,Chrome,...)

  • 使用Zombie.js,您的页面将在新的执行环境中运行

  • 使用Jasmine,您可以在浏览器(消费者使用)中测试其典型的怪癖

  • 使用Zombie.js,您可以在新浏览器中使用新怪癖测试应用程序

Jasmine示例:

    // spy on other module to know "method" was called on it
    spyOn(otherModule, "method");

    // create module
    let module = new Module(otherModule),
        returnValue;

    // calls otherModule.method() with the passed value too; always returns 42
    returnValue = module(31415);

    // assert result and interaction with other modules
    expect(returnValue).toBe(42);
    expect(otherModule.method).toHaveBeenCalledWith(31415);

Zombie.js示例:

    // create browser
    const browser = new Browser();
    // load page by url
    browser.visit('/signup', function() {
        browser
            // enter form data by name/CSS selectors
            .fill('email', 'zombie@underworld.dead')
            .fill('password', 'eat-the-living')
            // interact, press a button
            .pressButton('Sign Me Up!', done);
    });

    // actual test for output data
    browser.assert.text('title', 'Welcome To Brains Depot');

Zombie.js,像Webdriver / Selenium,不能替代像Jasmine,Mocha这样的单元测试框架。