Muhammed Senussi
Muhammed Senussi
  • Muhammed Senussi
Most of Your Angular Tests Do Not Need TestBedAngular

TestBed exists to configure Angular’s dependency injection and compile templates. If your test does neither, it is paying for both.

What to test how

  • Services and pure logic: construct the class with plain objects for dependencies. No TestBed, no async, no fixtures.
  • Component logic: with signals and standalone components, an instance can often be created directly and its methods called, which covers most of the interesting behaviour.
  • Templates and interaction: TestBed, or better, a component harness that tests what a user can do rather than which class is present.

The gain is not only speed, although a suite going from four minutes to forty seconds changes whether people run it. It is that a test constructed without a framework fails for one reason, while a TestBed test can fail because of a missing provider in a module you did not write.

2 Comments

  • Daan Visser

    June 24, 2025

    Four minutes to forty seconds is exactly our numbers after doing this. People started running tests locally again.

    • Muhammed Senussi

      Muhammed Senussi

      AuthorJune 24, 2025

      That second-order effect is the real prize. A suite nobody runs locally is a suite that only fails in CI, which is the most expensive place to find out.

Leave a comment