【问题标题】:Database integration tests with Jasmine使用 Jasmine 进行数据库集成测试
【发布时间】:2014-02-19 15:31:46
【问题描述】:

我想保证在 Jasmine 集成测试后关闭与数据库的连接。这就是我目前所拥有的——它会确保数据库连接正确关闭吗?

"use strict";

describe("MyCtorFunction", function () {

  describe("myMethod", function () {
    var _db = null,
        _testContext = null;

    beforeEach(function () {
      _testContext = {};
      new DbHelper().openConnection(function (err, dbConnection) {
        if (err) {
          throw err;
        }

        _db = dbConnection;
      });

      waitsFor(function () {
        return _db;
      }, "establishing a connection to the database.", 5000);
    });

    afterEach(function () {
      waitsFor(function () {
        return _testContext.assertions.callCount === 1;
      }, "waiting for the assertions to be called.", 5000);

      runs(function () {
        if (_db) {
          _db.close();
          _db = null;
        }
      });
    });

    it("should do something", function () {
      runs(function () {
        //arrange
        _testContext.assertions = assertions;
        spyOn(_testContext, "assertions").andCallThrough();

        //act (_testContext.assertions invoked as callback)
        new MyCtorFunction(_db).myMethod(_testContext.assertions);

        //assert
        function assertions(err, config) {
          expect(config).toNotBe(null);
          //etc.
        }
      });
    });
  });
});

【问题讨论】:

    标签: javascript integration-testing jasmine


    【解决方案1】:

    不,假设如下:

    • 测试期间网络连接没有丢失
    • 断言本身没有语法或引用错误
    • andCallThroughmyMethod 中没有错误

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-07
      • 2019-09-06
      • 1970-01-01
      • 1970-01-01
      • 2021-03-11
      相关资源
      最近更新 更多