我怎么可以自动与约曼和功放都E2E和单元测试; AngularJS? [英] How can I automate both E2E and unit tests with Yeoman & AngularJS?
问题描述
我使用的约曼和发电机角管理AngularJS应用程序,但我有自动化测试的麻烦
运行咕噜测试
将运行单元测试一次。我能得到端到端的测试后,单元测试运行由 Gruntfile.js
改变因缘配置块,加入E2E:
因果报应:{
// ...
E2E:{
CONFIGFILE:卡玛e2e.conf.js',
singleRun:真
}
},
大:现在,当我键入咕噜测试
所有测试运行。但他们只运行一次,有一个大的开销(启动指南针,运行服务器,启动浏览器过程等)。相反,服务器和Chrome过程应保持运行,当我保存测试,测试应该重新运行。
我可以通过修改实现这一目标既 karma.conf.js
和卡玛e2e.conf.js
和设置 singleRun = TRUE
,然后运行人缘启动
在一个终端窗格和因缘开始因缘-e2e.conf.js
在另一个。没有提供在因果报应CONFIGS冲突的端口(他们在默认情况下这样做)的,这个工程。现在,我绕过呻吟,只是在做我自己的事情(这似乎有点傻,因为咕噜应该使事情变得更容易)。
反正多了一些改变(修正?)之后 - 不详细,简洁 - 这工作,但并没有削减它:我现在已经运行两个不同的命令,并保持眼睛上的两个不同的终端窗格。肯定有更好的办法。
如何运行一个命令适当地看我的测试文件并重新运行测试?
奖金的问题:为什么在地球上没有提供该功能是什么?难道仅仅一个发电机的角度没有足够的时间来实现这个东西的开发者(S)的问题吗?我问,因为我才刚刚进入角/约曼/噶(如你可能已经注意到了),感觉既E2E和单元测试的自动化测试的工作流是至关重要的。
正如我在你的问题的评论中提到 - PhantomJS节省了很多的麻烦。除此之外,我相信你可以从你的Gruntfile内处理一切,只是继续运行咕噜测试
来启动整个事情。
咕噜 - 卡玛允许一些方便的附加组件的业力的选择完全定制。
从文档:
...
您可以直接覆盖任何的配置文件的设置:
因果报应:{
单位:{
CONFIGFILE:karma.conf.js',
runnerPort:9999,
singleRun:真实,
浏览器:['PhantomJS']
}
}
块引用>
共享的Configs
如果有多个目标,它可能有助于共享通用
它们之间的配置设置。咕噜 - 卡玛通过支持此
使用选项属性:因果报应:{
选项:{
CONFIGFILE:karma.conf.js',
runnerPort:9999,
浏览器:['铬','火狐']
},
连续: {
singleRun:真
浏览器:['PhantomJS']
},
开发:{
记者:点
}
}
块引用>此外,你可能想约曼的<一来窥探href=\"https://github.com/yeoman/generator-angular/blob/4408413e1a1a55472687962c91fb52f11292e22f/templates/common/Gruntfile.js\">generator-angular Gruntfile code 来看看还有什么可以提供或至少mockable。
I'm using Yeoman and generator-angular to manage AngularJS apps, but I'm having trouble with automated testing.
Running
grunt test
will run unit tests once. I can get E2E tests to run after unit tests by altering the karma config block inGruntfile.js
, adding e2e:karma: { //... e2e: { configFile: 'karma-e2e.conf.js', singleRun: true } },
Great: now when I type
grunt test
all tests are run. But they're only run one time, and there's a big overhead (starting compass, running the server, launching the Chrome processes, etc.). Instead, the server and Chrome processes should remain running and, when I save a test, tests should be re-run.I can achieve this by modifying both
karma.conf.js
andkarma-e2e.conf.js
and settingsingleRun = true
, then runningkarma start
in one terminal pane, andkarma start karma-e2e.conf.js
in another. Provided none of the ports in the karma configs conflict (which they do by default), this works. Now I'm bypassing Grunt and just doing my own thing (which seems a little silly, as Grunt is supposed to make things easier).Anyway, after a few more changes (fixes?) — not detailed for brevity — this works but doesn't cut it: I now have to run two different commands and keep an eye on two different terminal panes. Surely there's a better way.
How can I run a single command to watch my test files and re-run tests appropriately?
Bonus question: why on Earth is this functionality not provided as is? Is it just a question of the developer(s) of generator-angular not having enough time to implement this stuff? I ask because I'm only just getting into Angular/Yeoman/Karma (as you probably noticed), and feel that automated testing of both E2E and unit tests are crucial to workflow.
解决方案As I mentioned in a comment to your question - PhantomJS saves a lot of hassle. That aside, I believe you can handle everything from within your Gruntfile and just continue to run
grunt test
to start the whole thing.grunt-karma allows full customization of your karma options with some handy add-ons.
From the docs:
....
You can override any of the config file's settings directly:
karma: { unit: { configFile: 'karma.conf.js', runnerPort: 9999, singleRun: true, browsers: ['PhantomJS'] } }
Sharing Configs
If you have multiple targets, it may be helpful to share common configuration settings between them. Grunt-karma supports this by using the options property:
karma: { options: { configFile: 'karma.conf.js', runnerPort: 9999, browsers: ['Chrome', 'Firefox'] }, continuous: { singleRun: true browsers: ['PhantomJS'] }, dev: { reporters: 'dots' } }
Additionally you may want to snoop around in Yeoman's generator-angular Gruntfile code to see what else may be available or at least mockable.
这篇关于我怎么可以自动与约曼和功放都E2E和单元测试; AngularJS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!