2

我正在尝试让 Jasmine 与 Visual Studio 测试资源管理器一起工作。所以,我的测试文件看起来像这样:

/// <reference path="../wwwroot/lib/angular/angular.min.js" />
/// <reference path="../wwwroot/lib/angular-mocks/angular-mocks.js" />
/// <reference path="../wwwroot/lib/jasmine/lib/jasmine-core/jasmine.js" />

/// <reference path="../wwwroot/lib/angular-arrays/dist/angular.arrays.js" />
/// <reference path="../wwwroot/lib/angular-simple-cache/dist/simplecache.js" />
/// <reference path="../wwwroot/lib/angular-toastr/dist/angular-toastr.tpls.min.js" />
/// <reference path="../wwwroot/lib/ng-file-upload/ng-file-upload.min.js" />

/// <reference path="../app/common/common.js" />
/// <reference path="../app/common/services.js" />

var _sharedProductHandler,
    _pricingProducts,
    _availabilityProducts;

beforeEach(module('piiick.common'));
beforeEach(inject(['SharedProductHandler', function (sharedProductHandler) {
    _sharedProductHandler = sharedProductHandler;

    _pricingProducts = [{
        productId: 0
    }];
    _availabilityProducts = [{
        productId: 0
    }];
}]));

describe('Service: SharedProductService', function () {
    it('We have a list of pricing products', function () {
        expect(_pricingProducts.length).toBeGreaterThan(0);
    });

    it('We have a list of availability products', function () {
        expect(_availabilityProducts.length).toBeGreaterThan(0);
    });
});

如果我在浏览器中打开测试运行良好。但我希望它们出现在测试资源管理器中。我为测试资源管理器安装了 Chutzpah 适配器,但我的测试没有出现在那里。我读到您可以使用 chutzpah.json 文件添加设置,所以我这样做了,但我无法让我的测试出现在测试资源管理器中。我认为值得一提的是,我使用的是 Visual Studio 2015。

有谁知道如何让我的测试显示在测试资源管理器中?

4

1 回答 1

1

是的,我解决了这个问题.. chutzpah.json 文件需要在根目录中(它可以在任何地方,但路径设置必须相对于 json 文件所在的位置。我的看起来像这样:

{
  "Framework": "jasmine",
  "References": [
    { "Path": "wwwroot/lib/angular/angular.min.js" },
    { "Path": "wwwroot/lib/angular-mocks/angular-mocks.js" },
    { "Path": "wwwroot/lib/jasmine/lib/jasmine-core/jasmine.js" },

    { "Path": "wwwroot/lib/angular-arrays/dist/angular.arrays.js" },
    { "Path": "wwwroot/lib/angular-simple-cache/dist/simplecache.js" },
    { "Path": "wwwroot/lib/angular-toastr/dist/angular-toastr.tpls.min.js" },
    { "Path": "wwwroot/lib/ng-file-upload/ng-file-upload.min.js" },

    { "Path": "app/common/common.js" },
    { "Path": "app/common/services.js" }
  ],

  "Tests": [
    { "Path": "tests" }
  ]
}

规范文件不再需要任何引用,因此看起来像这样:

var _sharedProductHandler,
    _pricingProducts,
    _availabilityProducts;

beforeEach(module('piiick.common'));
beforeEach(inject(['SharedProductHandler', function (sharedProductHandler) {
    _sharedProductHandler = sharedProductHandler;

    _pricingProducts = [{
        productId: 0
    }];
    _availabilityProducts = [{
        productId: 0
    }];
}]));

describe('Service: SharedProductService', function () {
    it('We have a list of pricing products', function () {
        expect(_pricingProducts.length).toBeGreaterThan(0);
    });

    it('We have a list of availability products', function () {
        expect(_availabilityProducts.length).toBeGreaterThan(0);
    });
});

仅供我自己参考, bower.json 只需要这两个:

{
  "name": "ASP.NET",
  "private": true,
  "dependencies": {
    "angular-mocks": "^1.5.5",
    "jasmine": "^2.4.1"
  },
  "ignore": [
    "tests"
  ]
}
于 2016-05-23T22:27:32.710 回答