我们应该在单元测试时使用 Angular TestBed 吗?

Should we use Angular TestBed while unit testing?

我们应该在单元测试时使用 Angular TestBed 吗?还是保留用于 E2E/Component 测试?

Angular 文档说 You should write isolated unit tests for pipes and services. 独立的单元测试不需要 Testbed。 (https://angular.io/guide/testing#isolated-unit-tests)
对于 Angular 组件测试,您很可能希望使用 Testbed,我仍将其视为单元测试。现在说这个,我应该再次引用文档说

Good developers write both kinds of tests for the same application part, often in the same spec file. Write simple isolated unit tests to validate the part in isolation. Write Angular tests to validate the part as it interacts with Angular, updates the DOM, and collaborates with the rest of the application.

希望对您有所帮助。