2013-04-16 92 views
23

我似乎有让我的茉莉花单元测试,实际执行的问题。我已经验证了我的所有脚本都得到通过设置日志级别到LOG_DEBUG加载。我的单元测试是相同的服务测试@https://github.com/angular/angular-seed/blob/master/test/unit/servicesSpec.js噶不执行任何单元测试

而且,我已经使用Testacular(之前它改名为噶),我不记得有这个问题。我似乎让Chrome运行,但我不得不手动点击“调试”按钮。即使我点击这个按钮,我的测试也不会运行。

系统细节:

  • Windows 7的
  • 节点v0.10.4
  • 铬26.0.14
  • 噶0.8.5(安装了3个警告 - 2所损失的精度和一个'没有定义内联函数v8 :: Persistent v8 :: Persistent :: New(v8 :: Handle)')

这是我的模块代码(脚本/ 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' 
]); 

这里是我的规格(测试/单位/ 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; 
+0

我想我有这个漂亮的晚了,但我认为你必须设置要么'singleRun'或'autoWatch'为true。 – fodma1

回答

11

我最后的回答是错误的(将JASMINE和JASMINE_ADAPTER行移到angular.js行下面)。它解决了这个特定的问题,但创建了其他问题。相反,我做了什么来解决它是只指定角嘲笑文件,而不是angular- *,就像这样:

JASMINE, 
    JASMINE_ADAPTER, 
    'Vendor/angular-1.0.6/angular.js', 
    'Vendor/angular-1.0.6/angular-mocks.js', 
    'Vendor/json2/json2.js', 
    'Vendor/jquery/jquery-1.8.2.js', 
    'Vendor/amplify/amplify.js', 
    'Scripts/main.js', 
    'Test/unit/*.js' 
+0

感谢您的帮助rquinn,任何想法为什么有所有角JS文件包括导致测试不运行? – Darren

+5

这是因为用于端到端测试的角度场景文件。我认为这和angular-mocks文件有冲突。 –

+1

感谢这帮了我,我发现可以使用排除如下跳过情况文件。 – Darren

13

另外,您可以使用您karma.conf.js排除部分

exclude = [ 
    'Vendor/angular-1.0.6/angular-scenario.js' 
]; 
14

我刚刚遇到了同样的问题,我发现我必须在Karma自动运行测试之前设置autoWatch = true

6

如果您尝试使用JASMINE和JASMINE_ADAPTER解决此问题,则不再支持此功能(至少在Karma版本0.10.2上)。

而是使用:

frameworks: ['jasmine'] 

在噶配置文件。你可以阅读关于这个here

我还发现,我的文件阵列我为一个模式设置included: falseincluded仅在您想手动包含Javascript文件时使用(例如,如果您将使用require.js)。如果所有的测试将从该模式被加载,你会看到类似的消息:由于一点也没有包括含测试文件

PhantomJS 1.9.2 (Linux): Executed 0 of 0 ERROR (0.151 secs/0 secs) 

。从文件阵列模式我,因为如果包括未指定默认的解决了这个拆卸included: falsetrue

7

我尝试了所有上面没有成功,直到最后......

在我karma.conf.js我删除了requirejs依赖,如:

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

到:

frameworks: ['jasmine'], 
1

在我的案例singleRun被设置为false

解决方案 // Continuous Integration mode // if true, Karma captures browsers, runs the tests and exits singleRun: true