行动和测试隔离 [英] Isolation of actions and tests

查看:186
本文介绍了行动和测试隔离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试重构我的code。我知道,如果我有几个期待他们应该在'它'被孤立。我试着去理解我怎么能代替这样写:

I try to refactor my code. I know that if I have several expectations they should be isolate in 'it'. I try to understand how I can write instead this:

describe('my scenario should make', function () {

  var config = browser.params;
  var url = config.listOfReferencesUrl,
      grid,
      numberField;

  it('test1', function () {

    browser.get(url);
    browser.executeScript("icms.go('WEB_INQ_PROC', 'InquiryList', null, 0)");

    grid = psGrid(by.css("table[class='n-grid']"));
    numberField = grid.getQuickFilter(1);
    numberField.click().sendKeys("Hello!");

    since('fail1').expect(numberField.getInputText()).toEqual("");
  });

  it('test2', function () {
    since('fail2').expect(numberField.getInputText()).toEqual("Hello!");
  });

});

事情是这样的:

    describe('my scenario should make', function () {

      var config = browser.params;
      var url = config.listOfReferencesUrl,
          grid,
          numberField;

 *********Make this part of code ONES before all tests in spec ****
    browser.get(url);
    browser.executeScript("icms.go('WEB_INQ_PROC', 'InquiryList', null, 0)");

    grid = psGrid(by.css("table[class='n-grid']"));
    numberField = grid.getQuickFilter(1);
    numberField.click().sendKeys("Hello!"); 
*******************************************************************   
      it('test1', function () {
        since('fail1').expect(numberField.getInputText()).toEqual("");
      });

      it('test2', function () {
        since('fail2').expect(numberField.getInputText()).toEqual("Hello!");
      });

    });

也许有人有一个想法,我怎么能这样做呢?

Maybe somebody have an idea how I can do this?

推荐答案

要回答你的问题,如果你想运行code之前曾经所有测试,然后使用的 beforeAll()的茉莉2.可在这里功能是一个示例 -

To answer your question, if you want to run your code once before all tests then use beforeAll() function available in Jasmine 2. Here's a sample -

beforeAll(function(){
    //Write your code here that you need to run once before all specs
});

您可以使用 beforeEach()的茉莉可功能来运行在测试之前,规范各一次。下面是一个示例 -

You can use beforeEach() function available in Jasmine to run it each time before a test spec. Here's a sample -

beforeEach(function(){
    //Write your code here that you need to run everytime before each spec
});

如果您在获得这些功能的工作,然后更新插件的最新版本,然后尝试运行它面临的问题。还可以使用框架:jasmine2 conf.js 文件

If you are facing issue in getting these functions to work, then update your plugins to latest version and then try running it. Also use the framework: 'jasmine2' in your conf.js file

希望这有助于。

这篇关于行动和测试隔离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆