unit-test-quality/test-data-management penalise real in-memory implementations and require mocks

オープン
#29 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
静か
技術スタック
typescript
領域
testing-qa

調査の方向性

Start by locating the rules and tests for unit-test-quality-standards and test-data-management, then trace how they determine whether tests use mocks. The issue offers two alternative directions, so clarify which behavior is wanted before changing anything. Done means the tests cover the chosen policy and real in-memory implementations are no longer penalized unfairly.

索引モデルが issue の本文から書いたものです。

説明

enhancement

Version: 7.17.6
Laws: unit-test-quality-standards, test-data-management

What happens

Both laws report against test suites that deliberately use real in-memory
implementations instead of mocks:

• Dependencies found but no mocking detected in .../launch.page.spec.ts
• Dependencies found but no mocking detected in .../capability-matrix.spec.ts
• External dependencies are not properly mocked in tests

Every one of those files is a suite we would hold up as an example. The laws
are asking us to weaken them.

Why this is the wrong direction

A mock asserts that the code agrees with the test author's belief about a
collaborator, rather than with the collaborator. Two concrete cases from this
repository:

1. InMemoryPlatformCapabilityService runs the same resolution function
and the same capability matrix as production. Only the reported environment
differs. Mocking it would mean asserting against a hand-written table that can
drift from the real matrix — which is exactly the bug the tests exist to catch.

2. InMemoryResourceEnvironment keeps a real monotonic clock and a real
task queue that the test advances. It replaced a faked-timer approach precisely
because fake timers hide the ordering bugs a polling primitive is prone to:
overlapping refreshes, a stale alarm firing after teardown, a poll scheduled
from inside a finally.

Both are strictly stronger than mocking the collaborator away. Under these laws
they score worse than a suite full of jest.fn() that asserts nothing about
real behaviour.

That is the definition of a checkbox that lies, and it is the one thing our
engineering canon forbids outright — so we are reporting it rather than
complying, and rather than waiving it.

Suggested fix

Two options, either would work:

  1. Detect test doubles by role, not by framework. A class named
    InMemory* / Fake* / Stub* injected in place of a real collaborator is
    a test double. The current check appears to look only for a mocking library.
  2. Invert the law toward the property that matters: "a unit test must not
    reach real I/O — no network, no filesystem, no wall clock". That is what
    mocking is a means to, and it can be detected directly. A suite using real
    in-memory implementations passes it honestly; a suite that quietly hits the
    network fails it, which today's version does not catch.

(2) would also have caught a genuine bug in a sibling repository, where a test
was found to be making a live network call.

主要言語
TypeScript
スター
0
フォーク
0
平均マージ
38分
マージ済み PR(30日)
96

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Rule-Of-Code/RoC のほかの issue

Rule-Of-Code/RoC の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。