我知道e2e测试的角度有个beforeEach进行单独测试......但是我正在寻找整个套件的升级级别。任何人都知道在整个测试套件执行之前运行一段代码的方法吗?Angular e2e/Karma - Before Suite block?
2
A
回答
1
如果你不介意的块是运行在你的浴室你可以窝每一个测试你的测试,并有beforeEach
在最高水平,例如,
describe("Entire Suite", function() {
beforeEach(function(){
// Executed for every it in the entire suite
});
it('Test', function() {
// Only the first beforeEach will be called prior to this test.
});
describe("Subset Suite", function(){
beforeEach(function(){
// Executed for every it in this subset suite
});
it('Subtest', function() {
// Both beforeEach blocks will have been called prior to this test.
});
});
然而,主要beforeEach将执行之前它在整个套件中阻塞。如果你想让代码只执行一次,那么这不是你的解决方案。
3
我需要做的这个运行了一堆,需要一个用户登录的测试,所以我创建了一个文件karma.suiteInitialize.js
用下面的代码:
(function() {
'use strict';
angular
.module("app")
.run(testInitialize);
testInitialize.$inject = ['userService'];
function testInitialize(userService) {
userService.setUser({ UserName: 'Test user'});
// if (userService.isLogged())
// console.log("Test user logged in");
}
})();
,然后只将它添加到karma.config.js
后立即应用程序文件如:
files: [
'../Scripts/angular.js',
'../Scripts/angular-mocks.js',
'../Scripts/angular-route.js',
'../Scripts/angular-filter.js',
'../Scripts/angular-resource.js',
'../Scripts/angular-scroll.min.js',
'app/app.module.js',
'app/**/*.js',
'karma.suiteInitialize.js',
'tests/**/*.js',
'app/**/*.html'
]
..而这一切都花了。这不会减少登录用户的呼叫数量(它仍然会发生在每个测试中),但它确实使其变得方便。
相关问题
- 1. @using block before @ Html.BeginForm
- 2. 在RSpec中,before(:suite)和before(:all)之间有什么区别?
- 3. 如何在RSpec的before(:suite)/ before(:all)钩子中访问标签过滤器?
- 4. 将display:inline-block添加到:before或之后将使webfont消失
- 5. mongoose mpromise onResolve before before before
- 6. @Before Suite和@BeforeTest方法在TestNG中执行时不会被调用
- 7. 像PIE一样破坏CSS1和CSS2(如inline-block,:before,:after)在IE7中工作?
- 8. PyInstaller和Enthought Suite
- 9. 使用WeifenLuo DockPanel Suite
- 10. Consuming SOA Suite WSDL SOAP
- 11. error:expected'} before else
- 12. POP-Before-SMTP
- 13. error'expected')'before'*'token
- 14. afterEach before it
- 15. Button_click before Page_load
- 16. error:expected')'before':'token
- 17. “SyntaxError:missing; before statement”
- 18. PrepareForSegue before didSelectRowAtIndexPath
- 19. prepareForSegue before performSegue
- 20. 预计{before destructor
- 21. error'expected')'before'炸弹'
- 22. jquery selector before-last
- 23. return finally before finally
- 24. Kostache - before()方法
- 25. NSString“Expected”:'before']'token'error
- 26. @Before和@Transactional
- 27. PyMC3 large MvNormal before
- 28. error:expected')'before';'或'}'token
- 29. block compete.com
- 30. Block Applications