gpt4 book ai didi

unit-testing - Karma 没有执行任何单元测试

转载 作者:行者123 更新时间:2023-12-03 10:33:39 26 4
gpt4 key购买 nike

我似乎在让我的 Jasmine 单元测试实际执行时遇到问题。我已经通过将 logLevel 设置为 LOG_DEBUG 来验证我的所有脚本都被加载了。我的单元测试与服务测试 @ https://github.com/angular/angular-seed/blob/master/test/unit/servicesSpec.js 相同.

另外,我使用过 Testacular(在它更名为 Karma 之前),我不记得有这个问题。我似乎让 Chrome 运行,但我必须手动点击“调试”按钮。即使我按下此按钮,我的测试也不会运行。

系统详情:

  • window 7
  • 节点 v0.10.4
  • Chrome 26.0.14
  • Karma 0.8.5(安装了 3 个警告 - 2 个精度损失和一个“内联函数 v8::Persistent v8::Persistent::New(v8::Handle) 没有定义”)

  • 这是我的模块代码(Scripts/main.js):
    angular.module('sb.services', []).value('version', '0.0.1').value('amplify', amplify);
    angular.module('sb.directives', []);
    angular.module('sb.filters', []);
    angular.module('sb.controllers', []).controller('SbController', [
    '$scope',
    'amplify',
    function ($scope, amplify) {
    $scope.message = 'Hello World! (amplify exists?=' + !!amplify + ')';
    }
    ]);
    angular.module('sb', [
    'sb.services',
    'sb.directives',
    'sb.filters',
    'sb.controllers'
    ]);

    这是我的规范(Test/unit/servicesSpec.js):
    'use strict';

    describe('my services', function () {
    beforeEach(module('sb.services'));

    describe('version', function () {
    it('should return current version', inject(function(version) {
    expect(version).toEqual('0.0.1');
    }));
    });
    });

    这是我的 karma.conf.js 文件:
    // Karma configuration
    // Generated on Mon Apr 15 2013 20:56:23 GMT-0400 (Eastern Daylight Time)


    // base path, that will be used to resolve files and exclude
    basePath = '';


    // list of files / patterns to load in the browser
    files = [
    JASMINE,
    JASMINE_ADAPTER,
    'Vendor/angular-1.0.6/angular.js',
    'Vendor/angular-1.0.6/angular-*.js',
    'Vendor/json2/json2.js',
    'Vendor/jquery/jquery-1.8.2.js',
    'Vendor/amplify/amplify.js',
    'Scripts/main.js',
    'Test/unit/*.js'
    ];


    // list of files to exclude
    exclude = [

    ];


    // test results reporter to use
    // possible values: 'dots', 'progress', 'junit'
    reporters = ['progress'];


    // web server port
    port = 9876;


    // cli runner port
    runnerPort = 9100;


    // enable / disable colors in the output (reporters and logs)
    colors = true;


    // level of logging
    // possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
    logLevel = LOG_WARN;


    // enable / disable watching file and executing tests whenever any file changes
    autoWatch = false;


    // Start these browsers, currently available:
    // - Chrome
    // - ChromeCanary
    // - Firefox
    // - Opera
    // - Safari (only Mac)
    // - PhantomJS
    // - IE (only Windows)
    browsers = ['Chrome'];

    junitReporter = {
    outputFile: 'Test/out/unit.xml',
    suite: 'unit'
    };


    // If browser does not capture in given timeout [ms], kill it
    captureTimeout = 60000;


    // Continuous Integration mode
    // if true, it capture browsers, run tests and exit
    singleRun = false;

    最佳答案

    我尝试了以上所有方法都没有成功,直到最后......

    在我的 karma.conf.js我删除了 需要js 依赖,例如:

        frameworks: ['jasmine', 'requirejs'],

    到:
        frameworks: ['jasmine'],

    关于unit-testing - Karma 没有执行任何单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16028647/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com