【问题标题】:AngularJS, Jasmine and Visual Studio 2015 Test ExplorerAngularJS、Jasmine 和 Visual Studio 2015 测试资源管理器
【发布时间】:2016-05-23 17:33:47
【问题描述】:

我正在尝试让 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 适配器,但我的测试没有出现在那里。 我read that you can use a chutzpah.json file to add settings,所以我这样做了,但我无法让我的测试出现在测试资源管理器中。 我认为值得一提的是,我使用的是 Visual Studio 2015。

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

【问题讨论】:

    标签: visual-studio jasmine chutzpah test-explorer


    【解决方案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" }
      ]
    }
    

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

    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"
      ]
    }
    

    【讨论】:

    • 很高兴你知道了!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多