0

在“描述”测试套件的开始和结束时运行一些代码是否有一些技巧?

我正在寻找类似于 XUnit 的 setUpClass/tearDownClass 的东西

在这个例子中,我想在所有测试之前只运行一次“login_as_admin”,在所有测试之后只运行一次“logout”。

谢谢!

这是示例代码。

/*
Functional tests.
*/

describe('Services Page', function() {

    it('setUpClass', function() {
        login_as_admin()
    })

    /*
    Before each test make sure we are on the services page.
    */
    setup(function() {
        browser().navigateTo('/PAGE_UNDER_TEST')
    })

    it(
    'Click on add service will get us to the Add service page.',
    function() {
        element('#add-service').click()

        expect(browser().location().path()).toBe('/services/_add')
    })

    it(
    'Click on edit service will get us to the Edit service page.',
    function() {
        element('#edit-service').click()

        expect(browser().location().path()).toBe('/services/local-manager')
    })

    it('tearUpClass', function() {
        logout()
    })

})
4

1 回答 1

1

茉莉花 ( 1 ) 和 ( 2 )有一些补丁支持这样做。然而,它们似乎没有得到很好的维护。正是因为这个原因,我已经从 Jasmine 搬到了Mocha 。

于 2014-04-11T13:14:57.533 回答