我使用karma来运行测试。我有很多测试,运行所有的测试是一个非常慢的过程。我只想运行一个测试,以便花费更少的时间,因为所有测试都运行大约10分钟。
有可能吗?
发布于 2015-08-03 23:26:29
如果您使用的是Karma/Jasmine堆栈,请使用:
fdescribe("when ...", function () { // to [f]ocus on a single group of tests
fit("should ...", function () {...}); // to [f]ocus on a single test case
});..。和:
xdescribe("when ...", function () { // to e[x]clude a group of tests
xit("should ...", function () {...}); // to e[x]clude a test case
});当你在Karma/Mocha
describe.only("when ...", function () { // to run [only] this group of tests
it.only("should ...", function () {...}); // to run [only] this test case
});..。和:
describe.skip("when ...", function () { // to [skip] running this group of tests
it.skip("should ...", function () {...}); // to [skip] running this test case
});发布于 2015-07-15 00:20:46
更新: karma已经改变了。
现在使用fit()和fdescribe()
F代表专注!
发布于 2019-04-05 06:42:01
适用于Angular用户!
我知道两种方法:
最简单的方法是使用vscode-test-explorer扩展以及它的子angular-karma-test-explorer和jasmine-test-adapter,如果需要,您将获得要逐个运行的当前测试的列表:

对我来说,由于this bug的原因,我不能使用扩展方式,所以我最终修改了test.ts文件(正如Shashi所说的here ),只是为了在这里巩固这个答案,默认情况下上下文是这样的:
const context = require.context('./', true, /\.spec\.ts$/);你应该修改它的RegExp来匹配你想要测试的文件,例如,如果你想测试一个名为"my.single.file.custom.name.spec.ts“的文件,它将是这样的:
const context = require.context('./', true, /my\.single\.file\.custom\.name\.spec\.ts$/);有关require参数的更多详细信息,您可以在here at their wiki中找到。
目前有一个未解决的问题来改善他们目前的行为,你可以在他们的github页面(https://github.com/karma-runner/karma/issues/1507)上关注他们的进展。
https://stackoverflow.com/questions/26552729
复制相似问题