Ric*_*cha 8 javascript jasmine typescript karma-runner angular
我们来看下面的例子:
const listDefinition: any = {
module: "module",
service: "service",
listname: "listname"
};
@Component(...)
class MockTreeExpanderComponent extends TreeExpanderComponent {...}
class MockListConfigurationsService extends ListConfigurationsService {...}
describe('ColumnsListConfigurationsComponent Test cases', () => {
let fixture: ComponentFixture<ColumnsListConfigurationsComponent>;
let component: ColumnsListConfigurationsComponent;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [
ComponentToTest,
MockTreeExpanderComponent
],
providers: [
{ provide: TreeListConfigurationService, useClass: MockTreeListConfigurationService }
]
});
fixture = TestBed.createComponent(ComponentToTest);
component = fixture.componentInstance;
component.listDefinition = listDefinition;
fixture.detectChanges();
});
});
Run Code Online (Sandbox Code Playgroud)
如您所见,我有一个Mock组件(MockListViewerGridComponent)和service(ListConfigurationsService),一个配置变量(listDefinition)以及我想要测试的fixture和组件.
我的问题是关于performance和test memory management:
beforeEach或创建一个夹具beforeAll?通过这样做,我会有性能提升?谢谢!
我对第 3 点有一个答案
让我分享一下我自己的经历beforeAll。
我们在我们的一个应用程序中使用了beforeEach夹具创建,该应用程序花费了近 12 分钟来构建整个应用程序。为了each unit of work。
我们必须构建应用程序
1st time client side
2nd time on review branch和
3rd time release branch
几乎(合并)需要30 min提交unit of work。
现在,作为一个团队,这次与宾果游戏多次合作,head count of resources我们仅在应用程序构建过程中浪费了大量时间。
在某些时候,我们在本文的帮助下beforeEach替换了,并且它起作用了。我们能够将构建时间缩短约 80%。beforeAll
第 1 点和第 2 点的简短回答
1) 是的
2)最好创建单独的模拟服务。您可以在 before all 块内的存根的帮助下提供它的对象,并将所有模拟保存在同一个文件夹中。
providers: [
{ provide: XService, useClass: XServiceStub }
]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
424 次 |
| 最近记录: |