我知道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. Angular 2 block UI組件
- 5. 將display:inline-block添加到:before或之後將使webfont消失
- 6. mongoose mpromise onResolve before before before
- 7. @Before Suite和@BeforeTest方法在TestNG中執行時不會被調用
- 8. 像PIE一樣破壞CSS1和CSS2(如inline-block,:before,:after)在IE7中工作?
- 9. PyInstaller和Enthought Suite
- 10. Brew + suite-sparse421
- 11. Sonata Block Block SimpleBlock渲染
- 12. java.lang.OutOfMemoryError:Java堆空間 - Appium - TestNG Suite
- 13. @Before和@Transactional
- 14. prepareForSegue before performSegue
- 15. afterEach before it
- 16. error'expected')'before'炸彈'
- 17. error:expected')'before':'token
- 18. error:expected')'before'<'token
- 19. error:expected')'before';'或'}'token
- 20. NSString「Expected」:'before']'token'error
- 21. PrepareForSegue before didSelectRowAtIndexPath
- 22. error:expected'} before else
- 23. return finally before finally
- 24. 「SyntaxError:missing; before statement」
- 25. POP-Before-SMTP
- 26. jquery selector before-last
- 27. Kostache - before()方法
- 28. error'expected')'before'*'token
- 29. 預計{before destructor
- 30. Button_click before Page_load