{"slug": "unit-test-ai-guide-zero-hallucination-cross-stack-standard", "title": "Unit Test AI Guide — Zero Hallucination, Cross-Stack Standard", "summary": "A developer outlines a deterministic, zero-hallucination approach to AI-generated unit tests across Node.js, React, Python, Angular, and Laravel stacks. The guide mandates a single testing library per stack—Jest for Node.js and Angular, Vitest for React, pytest for Python, and Pest for Laravel—and relies on Cursor's .cursor/rules system to inject persistent, project-scoped instructions into every AI interaction, preventing hallucination at the source.", "body_md": "Focus:Unit Tests ONLY — no integration, no E2E\n\nStacks:Node.js (NestJS/Express) · React.js · Python · Angular · Laravel\n\nGoal:AI generates unit tests consistently, deterministically, without hallucination\n\nIDE:Cursor (Primary) + Claude (Secondary)\n\nDo not mix libraries. Pick one per stack, configure it fully, never deviate.\n\n| Stack | Library | Why This One |\n\n|---|---|---|\n\n| **Node.js / NestJS / Express** | `Jest`\n\n| Native DI mocking, `@nestjs/testing`\n\nbuilt around it, widest ecosystem |\n\n| **React.js** | `Vitest`\n\n+ `@testing-library/react`\n\n| Native Vite/ESM support, Jest-compatible API, 3–10x faster |\n\n| **Python** | `pytest`\n\n| De facto standard, fixture system eliminates boilerplate, best plugin ecosystem |\n\n| **Angular** | `Jest`\n\n(replace Karma) | Karma is deprecated in Angular 17+; Jest is the official migration target |\n\n| **Laravel** | `Pest`\n\n| Modern syntax, built on PHPUnit, higher signal-to-noise ratio |\n\nRule:If someone suggests a second library for the same stack, reject it. One library per stack, configured once, followed always.\n\n| Capability | Cursor | VS Code + Copilot | WebStorm |\n\n|---|---|---|---|\n\n| Project-level AI rules | ✅ `.cursor/rules/`\n\n| ❌ | ❌ |\n\n| Codebase-aware context | ✅ `@codebase`\n\n| Partial | Partial |\n\n| Run terminal + read output | ✅ Composer | ❌ | ❌ |\n\n| Multi-file generation | ✅ Agent mode | Limited | ❌ |\n\n| Custom instructions per filetype | ✅ | ❌ | ❌ |\n\n| MCP server integration | ✅ | ❌ | ❌ |\n\nCursor's `.cursor/rules/`\n\nsystem is the **only IDE-native mechanism** that injects persistent, project-scoped instructions into every AI interaction — this is what prevents hallucination at the source.\n\n```\nproject-root/\n\n├── .cursor/\n\n│   └── rules/\n\n│       ├── unit-test-global.mdc       ← applies to all files\n\n│       ├── unit-test-nestjs.mdc       ← applies to *.service.ts, *.guard.ts\n\n│       ├── unit-test-react.mdc        ← applies to *.tsx, *.component.tsx\n\n│       ├── unit-test-python.mdc       ← applies to *.py\n\n│       ├── unit-test-angular.mdc      ← applies to *.component.ts, *.service.ts\n\n│       └── unit-test-laravel.mdc      ← applies to *Service.php, *Model.php\n\n├── CLAUDE.md                          ← Claude project memory file\n\n└── ...\n```\n\nThese files are injected into every AI prompt automatically when working on matching files.\n\n**File: .cursor/rules/unit-test-global.mdc**\n\n```\n---\n\ndescription: Global unit test rules — applies to all files in this project\n\nglobs: [\"**/*.spec.ts\", \"**/*.test.ts\", \"**/*.spec.tsx\", \"**/*_test.py\", \"**/Test*.php\"]\n\nalwaysApply: true\n\n---\n\n# Unit Test Contract — MUST FOLLOW, NO EXCEPTIONS\n\n## What is a unit test here\n\n- Tests ONE class or function in complete isolation\n\n- ALL external dependencies are mocked — no real DB, no real HTTP, no real file system\n\n- Each test runs independently — no shared mutable state between tests\n\n- Runs in < 100ms\n\n## Structure: AAA — Always, Without Exception\n\nEvery test MUST have these three sections, with comments:\n```\n\n// Arrange — set up inputs, mocks, expected values\n\n// Act — call the single function/method under test\n\n// Assert — verify exactly one outcome\n\n```\n## Naming Convention — Mandatory\n\n- File: `[module-name].spec.ts` or `[module-name].unit.spec.ts`\n\n- Describe block: exact class or function name\n\n- It/test block: \"should [expected behavior] when [specific condition]\"\n\n  GOOD: \"should throw NotFoundException when user does not exist\"\n\n  BAD:  \"user not found\", \"test 1\", \"works correctly\"\n\n## What to test per function — minimum coverage\n\n1. Happy path — valid input → expected output\n\n2. Null/undefined input — how does it fail safely\n\n3. Empty input — empty string, empty array, zero\n\n4. Error path — when dependency throws, what happens\n\n5. Boundary — max length, negative numbers, boolean edge\n\n## What NOT to include in unit tests\n\n- Database queries (mock the repository)\n\n- HTTP calls (mock the service/axios/fetch)\n\n- File system operations (mock fs)\n\n- Timer behavior (use jest.useFakeTimers)\n\n- Random values (mock Math.random or faker with fixed seed)\n\n## AI Instruction\n\nWhen asked to generate a unit test:\n\n1. READ the function signature and types first\n\n2. IDENTIFY all dependencies (constructor args, imported modules)\n\n3. MOCK every dependency — never use real implementations\n\n4. Generate minimum 4 test cases per method (happy, null, error, edge)\n\n5. NEVER import from test doubles or assume what isn't in the source file\n\n6. If you are unsure of a type — ASK, do not assume\n```\n\n**File: .cursor/rules/unit-test-nestjs.mdc**\n\n```\n---\n\ndescription: NestJS unit test rules\n\nglobs: [\"src/**/*.service.ts\", \"src/**/*.guard.ts\", \"src/**/*.interceptor.ts\", \"src/**/*.pipe.ts\"]\n\n---\n\n# NestJS Unit Test Rules\n\n## Library: Jest + @nestjs/testing + jest-mock-extended\n\n## Always use Test.createTestingModule\n```\n\ntypescript\n\nconst module = await Test.createTestingModule({\n\nproviders: [\n\n```\nSubjectService,\n\n{ provide: DependencyService, useValue: mockDependency }\n```\n\n]\n\n}).compile();\n\n```\n## Mock Pattern — jest-mock-extended\n```\n\ntypescript\n\nimport { createMock } from '@golevelup/ts-jest';\n\n// OR\n\nimport { mock } from 'jest-mock-extended';\n\nconst mockUserRepo = mock();\n\n```\n## Never\n\n- Never use `new SubjectService()` directly — always use TestingModule\n\n- Never let `useValue` contain real implementations\n\n- Never test more than one service per describe block\n\n## Repository Mock Template\n```\n\ntypescript\n\nconst mockRepo = {\n\nfindOne: jest.fn(),\n\nsave: jest.fn(),\n\ndelete: jest.fn(),\n\nfindAll: jest.fn(),\n\nupdate: jest.fn(),\n\n};\n\n```\n## Required imports for every NestJS spec file\n```\n\ntypescript\n\nimport { Test, TestingModule } from '@nestjs/testing';\n\nimport { NotFoundException, BadRequestException } from '@nestjs/common';\n\nmarkdown\n\n**File: .cursor/rules/unit-test-react.mdc**\n\n```\n---\n\ndescription: React unit test rules\n\nglobs: [\"src/**/*.tsx\", \"src/**/*.component.tsx\", \"src/hooks/**/*.ts\"]\n\n---\n\n# React Unit Test Rules\n\n## Library: Vitest + @testing-library/react + @testing-library/user-event\n\n## Required setup in vitest.config.ts\n```\n\ntypescript\n\nexport default defineConfig({\n\ntest: {\n\n```\nenvironment: 'jsdom',\n\nglobals: true,\n\nsetupFiles: ['./src/test/setup.ts']\n```\n\n}\n\n})\n\n```\n## setup.ts\n```\n\ntypescript\n\nimport '@testing-library/jest-dom';\n\n```\n## Component test structure\n```\n\ntypescript\n\nimport { render, screen } from '@testing-library/react';\n\nimport userEvent from '@testing-library/user-event';\n\nimport { vi } from 'vitest';\n\n```\n## Mocking rules for React\n\n- Mock ALL hooks that call APIs: `vi.mock('../hooks/useUsers')`\n\n- Mock ALL context providers — wrap with test-specific providers\n\n- Mock router: use `MemoryRouter` from react-router-dom\n\n- NEVER mock internal state (useState) — test behavior, not implementation\n\n## Query priority (RTL best practice — mandatory)\n\n1. getByRole — prefer always\n\n2. getByLabelText — for forms\n\n3. getByText — for content\n\n4. getByTestId — LAST RESORT only, requires data-testid attribute\n\n## User event — always use userEvent, never fireEvent\n```\n\ntypescript\n\nconst user = userEvent.setup();\n\nawait user.click(button);\n\nawait user.type(input, 'value');\n\n```\n## Custom hook testing\n```\n\ntypescript\n\nimport { renderHook, act } from '@testing-library/react';\n\nconst { result } = renderHook(() => useMyHook());\n\nact(() => result.current.doSomething());\n\nexpect(result.current.value).toBe('expected');\n\ntypescript\n\n**File: .cursor/rules/unit-test-python.mdc**\n\n```\n---\n\ndescription: Python unit test rules\n\nglobs: [\"**/*.py\", \"!**/*migrations*\"]\n\n---\n\n# Python Unit Test Rules\n\n## Library: pytest + pytest-mock + factory-boy\n\n## File naming\n\n- Source: `app/services/user_service.py`\n\n- Test:   `tests/unit/test_user_service.py`\n\n- ALWAYS mirror the source directory structure under tests/unit/\n\n## Class under test — always use dependency injection\n```\n\npython\n\nclass UserService:\n\n``` python\ndef __init__(self, repo: UserRepository):\n\n    self.repo = repo\n```\n\nclass UserService:\n\n``` python\ndef __init__(self):\n\n    self.repo = UserRepository()  # can't mock this\n## Mock pattern — pytest-mock (mocker fixture)\n```\n\npython\n\ndef test_raises_when_user_not_found(mocker):\n\n```\nmock_repo = mocker.Mock()\n\nmock_repo.find_by_id.return_value = None\n\nservice = UserService(mock_repo)\n\nwith pytest.raises(UserNotFoundException):\n\n    service.get_user(\"missing-id\")\n## Async tests — pytest-asyncio\n```\n\npython\n\nimport pytest\n\n@pytest.mark.asyncio\n\nasync def test_async_service(mocker):\n\n```\nmock_repo = mocker.AsyncMock()\n\n...\n## Fixture pattern — for shared setup\n```\n\npython\n\n@pytest.fixture\n\ndef user_service(mocker):\n\n```\nrepo = mocker.Mock()\n\nreturn UserService(repo), repo\n```\n\ndef test_get_user_happy_path(user_service):\n\n```\nservice, repo = user_service\n\nrepo.find_by_id.return_value = User(id=\"1\", email=\"a@b.com\")\n\nresult = service.get_user(\"1\")\n\nassert result.email == \"a@b.com\"\n## Naming\n\n- File: `test_[module_name].py`\n\n- Function: `test_[expected_behavior]_when_[condition]`\n```\n\nmarkdown\n\n**File: .cursor/rules/unit-test-angular.mdc**\n\n```\n---\n\ndescription: Angular unit test rules\n\nglobs: [\"src/app/**/*.component.ts\", \"src/app/**/*.service.ts\", \"src/app/**/*.pipe.ts\", \"src/app/**/*.guard.ts\"]\n\n---\n\n# Angular Unit Test Rules\n\n## Library: Jest (NOT Karma — Karma is deprecated Angular 17+)\n\n## Migration from Karma to Jest (one-time)\n```\n\nbash\n\nng add @angular-builders/jest\n\n```\n## TestBed configuration — always minimal\n```\n\ntypescript\n\nawait TestBed.configureTestingModule({\n\nimports: [ComponentUnderTest], // standalone components\n\nproviders: [\n\n```\n{ provide: UserService, useValue: mockUserService }\n```\n\n]\n\n}).compileComponents();\n\n```\n## Service mock pattern\n```\n\ntypescript\n\nconst mockUserService = {\n\ngetUser: jest.fn(),\n\ncreateUser: jest.fn(),\n\n};\n\n```\n## Component test — check DOM behavior, not internal state\n```\n\ntypescript\n\nfixture.detectChanges(); // trigger ngOnInit\n\nconst button = fixture.debugElement.query(By.css('[data-testid=\"submit\"]'));\n\nbutton.nativeElement.click();\n\nfixture.detectChanges();\n\nexpect(fixture.debugElement.query(By.css('.error-msg'))).toBeTruthy();\n\n```\n## Pipe test — pure function, no TestBed needed\n```\n\ntypescript\n\nit('should transform date correctly', () => {\n\nconst pipe = new DateFormatPipe();\n\nexpect(pipe.transform(new Date('2024-01-01'))).toBe('Jan 1, 2024');\n\n});\n\n```\n## Guard/resolver test — inject and call directly\n```\n\ntypescript\n\nconst guard = TestBed.inject(AuthGuard);\n\nconst result = await guard.canActivate(mockRoute, mockState);\n\nexpect(result).toBe(false);\n\npython\n\n**File: .cursor/rules/unit-test-laravel.mdc**\n\n```\n---\n\ndescription: Laravel unit test rules\n\nglobs: [\"app/Services/**/*.php\", \"app/Models/**/*.php\", \"app/Http/Requests/**/*.php\", \"app/Actions/**/*.php\"]\n\n---\n\n# Laravel Unit Test Rules\n\n## Library: Pest (NOT PHPUnit directly — Pest wraps it with better syntax)\n\n## File location\n\n- Source: `app/Services/UserService.php`\n\n- Test:   `tests/Unit/Services/UserServiceTest.php`\n\n## Class under test — use constructor injection\n```\n\nphp\n\nclass UserService {\n\n```\npublic function __construct(\n\n    private readonly UserRepositoryInterface $repo\n\n) {}\n```\n\n}\n\n```\n## Mock pattern — Mockery (included with Pest/PHPUnit)\n```\n\nphp\n\nit('throws exception when user not found', function () {\n\n``` php\n// Arrange\n\n$repo = Mockery::mock(UserRepositoryInterface::class);\n\n$repo->shouldReceive('findById')->once()->andReturn(null);\n\n$service = new UserService($repo);\n\n// Act & Assert\n\nexpect(fn () => $service->getUser('abc'))\n\n    ->toThrow(UserNotFoundException::class);\n```\n\n});\n\n```\n## Data provider pattern (Pest datasets)\n```\n\nphp\n\nit('validates email format', function (string $email, bool $valid) {\n\n``` php\nexpect(validateEmail($email))->toBe($valid);\n```\n\n})->with([\n\n```\n['valid@email.com', true],\n\n['notanemail', false],\n\n['', false],\n\n['@nodomain.com', false],\n```\n\n]);\n\n``` php\n## What NOT to do in unit tests\n\n- Never call $this->get() or $this->post() — that is feature testing\n\n- Never use RefreshDatabase — that is feature/integration testing\n\n- Never resolve from service container — inject directly\n```\n\nmarkdown\n\nPlace this at project root. Claude reads it on every session automatically.\n\n**File: CLAUDE.md**\n\n```\n# Project: [Your Project Name]\n\n# Claude Unit Test Instructions\n\n## Stack\n\n- Backend: NestJS + TypeScript\n\n- Frontend: React + Vite + TypeScript\n\n- Testing: Jest (NestJS) + Vitest (React) + Pest (Laravel) + pytest (Python)\n\n## Unit Test Rules — NON-NEGOTIABLE\n\n### When asked to generate a unit test:\n\n1. NEVER generate integration or E2E tests unless explicitly asked\n\n2. ALWAYS mock every external dependency\n\n3. ALWAYS follow AAA (Arrange-Act-Assert) with comments\n\n4. ALWAYS generate minimum 4 cases: happy path, null/empty, error thrown, edge case\n\n5. NEVER use `any` type in TypeScript tests\n\n6. NEVER leave `TODO` comments in generated tests\n\n### Naming\n\n- NestJS: `[name].service.spec.ts` inside same directory as source\n\n- React: `[ComponentName].test.tsx` inside `__tests__/` or same directory\n\n- Python: `test_[module].py` under `tests/unit/`\n\n- Laravel: `[Name]Test.php` under `tests/Unit/`\n\n### Test should describe BEHAVIOR, not implementation\n\nGOOD: \"should return empty array when no users match search\"\n\nBAD: \"test getUserByFilter\"\n\n### If you are unsure of the correct mock structure:\n\n- Ask what the dependency interface looks like\n\n- Do NOT invent method names that don't exist in the source\n\n### Coverage target: 80% lines, 75% branches per module\n\n## Project Structure Reference\n\nsrc/\n\n  modules/\n\n    users/\n\n      users.service.ts\n\n      users.service.spec.ts   ← unit test lives here\n\n      users.repository.ts\n\n      users.repository.spec.ts\n```\n\nMCP (Model Context Protocol) servers extend AI capabilities. For unit testing, these are the relevant ones:\n\nCursor already has filesystem access. No extra MCP needed to read source files and generate tests. The `.cursor/rules/`\n\nsystem handles this.\n\n**1. @executeautomation/playwright-mcp-server**\n\nScope: E2E only — not relevant for unit tests\n\nSkip for this use case\n\n**2. @modelcontextprotocol/server-filesystem**\n\nGives Claude access to project files\n\nUse in Claude Desktop to read source → generate tests\n\nInstall: configured in `claude_desktop_config.json`\n\n**3. Custom Testing MCP (Build This — Highest Value)**\n\nBuild a lightweight MCP server that:\n\nReads a source file\n\nExtracts function signatures + types\n\nReturns structured JSON to Claude\n\nClaude generates tests from structure, not guesswork\n\n``` js\n// mcp-test-generator/src/index.ts\n\nimport { Server } from '@modelcontextprotocol/sdk/server/index.js';\n\nimport { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';\n\nimport * as ts from 'typescript';\n\nconst server = new Server({ name: 'test-generator', version: '1.0.0' }, {\n\n  capabilities: { tools: {} }\n\n});\n\nserver.setRequestHandler('tools/call', async (req) => {\n\n  if (req.params.name === 'extract_signatures') {\n\n    const { filePath } = req.params.arguments;\n\n    const signatures = extractFunctionSignatures(filePath); // parse AST\n\n    return { content: [{ type: 'text', text: JSON.stringify(signatures) }] };\n\n  }\n\n});\n\nfunction extractFunctionSignatures(filePath: string) {\n\n  // Use TypeScript compiler API to extract:\n\n  // - class name\n\n  // - method names\n\n  // - parameter types\n\n  // - return types\n\n  // - injected dependencies (constructor params)\n\n  const program = ts.createProgram([filePath], {});\n\n  const sourceFile = program.getSourceFile(filePath);\n\n  // ... AST traversal\n\n  return { className, methods, dependencies };\n\n}\n```\n\n**Why this matters:** When Claude receives typed signatures instead of raw source code, it cannot hallucinate — it generates tests from concrete types, not guesses.\n\n```\n// ~/Library/Application Support/Claude/claude_desktop_config.json (macOS)\n\n// %APPDATA%\\Claude\\claude_desktop_config.json (Windows)\n\n{\n\n  \"mcpServers\": {\n\n    \"filesystem\": {\n\n      \"command\": \"npx\",\n\n      \"args\": [\"-y\", \"@modelcontextprotocol/server-filesystem\", \"/path/to/your/project\"]\n\n    },\n\n    \"test-generator\": {\n\n      \"command\": \"node\",\n\n      \"args\": [\"/path/to/your/mcp-test-generator/dist/index.js\"]\n\n    }\n\n  }\n\n}\n// .cursor/mcp.json (project-level)\n\n{\n\n  \"mcpServers\": {\n\n    \"test-generator\": {\n\n      \"command\": \"node\",\n\n      \"args\": [\"./tools/mcp-test-generator/dist/index.js\"]\n\n    }\n\n  }\n\n}\n```\n\nThe root cause of AI hallucination in tests: AI invents method names, wrong mock structures, non-existent imports. These prompts eliminate that.\n\n```\nGenerate a unit test file for this [NestJS service / React component / Python class / Angular service / Laravel service].\n\nRules:\n\n- Library: [Jest / Vitest / pytest / Jest / Pest]\n\n- Test only THIS file — no integration\n\n- Mock ALL dependencies listed in the constructor/props\n\n- Follow AAA pattern with comments\n\n- Minimum 4 test cases per public method\n\n- Use ONLY methods/properties that exist in this source file\n\n- Do NOT import anything not shown in the source\n\n- Naming: \"should [behavior] when [condition]\"\nRead [filename].\n\nExtract:\n\n1. Class/function name\n\n2. All public methods with parameter types and return types\n\n3. All constructor dependencies (for mocking)\n\nThen generate the unit test file following CLAUDE.md rules.\n\nDo NOT assume any method exists unless you can see it in the source.\nFor each file in [directory], generate a corresponding .spec.ts file.\n\nProcess one file at a time.\n\nFor each file:\n\n  1. Read the source\n\n  2. List the public methods you found (confirm before generating)\n\n  3. Generate the test file\n\n  4. Show the test file path\n\nDo not proceed to the next file until the current one is confirmed.\n```\n\nAll stacks follow the same proximity principle: **test file lives next to source file**.\n\n```\nsrc/\n\n  modules/\n\n    users/\n\n      users.service.ts\n\n      users.service.spec.ts        ← unit test\n\n      users.repository.ts\n\n      users.repository.spec.ts     ← unit test\n\n      users.guard.ts\n\n      users.guard.spec.ts          ← unit test\nsrc/\n\n  components/\n\n    UserCard/\n\n      UserCard.tsx\n\n      UserCard.test.tsx            ← unit test\n\n      UserCard.stories.tsx         ← storybook (optional)\n\n  hooks/\n\n    useUserData.ts\n\n    useUserData.test.ts            ← unit test\napp/\n\n  services/\n\n    user_service.py\n\ntests/\n\n  unit/\n\n    services/\n\n      test_user_service.py        ← mirrors app/ structure\napp/\n\n  Services/\n\n    UserService.php\n\ntests/\n\n  Unit/\n\n    Services/\n\n      UserServiceTest.php         ← mirrors app/ structure\n```\n\nAll of this means nothing without enforcement. The pipeline is the final gate.\n\n```\nname: Unit Tests\n\non: [push, pull_request]\n\njobs:\n\n  nestjs-unit:\n\n    runs-on: ubuntu-latest\n\n    steps:\n\n      - uses: actions/checkout@v4\n\n      - uses: actions/setup-node@v4\n\n        with: { node-version: '20' }\n\n      - run: npm ci\n\n      - run: npm run test:unit -- --coverage --coverageThreshold='{\"global\":{\"lines\":80}}'\n\n  react-unit:\n\n    runs-on: ubuntu-latest\n\n    steps:\n\n      - uses: actions/checkout@v4\n\n      - uses: actions/setup-node@v4\n\n        with: { node-version: '20' }\n\n      - run: npm ci\n\n      - run: npx vitest run --coverage\n\n  python-unit:\n\n    runs-on: ubuntu-latest\n\n    steps:\n\n      - uses: actions/checkout@v4\n\n      - uses: actions/setup-python@v5\n\n        with: { python-version: '3.12' }\n\n      - run: pip install -r requirements-dev.txt\n\n      - run: pytest tests/unit/ --cov=app --cov-fail-under=80\n\n  laravel-unit:\n\n    runs-on: ubuntu-latest\n\n    steps:\n\n      - uses: actions/checkout@v4\n\n      - uses: shivammathur/setup-php@v2\n\n        with: { php-version: '8.3' }\n\n      - run: composer install\n\n      - run: ./vendor/bin/pest --coverage --min=80\n// package.json\n\n{\n\n  \"lint-staged\": {\n\n    \"src/**/*.service.ts\": [\"jest --findRelatedTests --passWithNoTests\"],\n\n    \"src/**/*.tsx\": [\"vitest related --run\"]\n\n  }\n\n}\n□ Install test library (one per stack — see Part 1)\n\n□ Configure jest.config.ts / vitest.config.ts / pytest.ini / pest.php\n\n□ Create .cursor/rules/ directory with all rule files from Part 3\n\n□ Create CLAUDE.md at project root from Part 4\n\n□ Add coverage thresholds to config\n\n□ Add pre-commit hooks (Husky for Node, pre-commit for Python)\n\n□ Add CI workflow from Part 8\n\n□ Create test factory files (one per major entity)\n\n□ Write first failing test → implement → green → commit\n□ Add test library without touching existing code\n\n□ Add .cursor/rules/ + CLAUDE.md\n\n□ Run coverage on existing code → document current baseline\n\n□ Pick 3 critical services → generate tests → set as new baseline\n\n□ Add CI with threshold = current baseline (not ideal — current)\n\n□ Raise threshold by 5% per sprint\nnpm install --save-dev jest ts-jest @types/jest @nestjs/testing jest-mock-extended @golevelup/ts-jest\n\nnpx ts-jest config:init\nnpm install --save-dev vitest @vitest/coverage-v8 @testing-library/react @testing-library/user-event @testing-library/jest-dom jsdom\npip install pytest pytest-cov pytest-mock pytest-asyncio factory-boy\nng add @angular-builders/jest\n\nnpm install --save-dev jest jest-preset-angular @types/jest\ncomposer require pestphp/pest pestphp/pest-plugin-laravel --dev\n\n./vendor/bin/pest --init\n```\n\n*Last updated: 2025 — verify library major versions before adopting*", "url": "https://wpnews.pro/news/unit-test-ai-guide-zero-hallucination-cross-stack-standard", "canonical_source": "https://dev.to/bhaumik-viitor/unit-test-ai-guide-zero-hallucination-cross-stack-standard-p18", "published_at": "2026-06-19 11:46:34+00:00", "updated_at": "2026-06-19 12:07:42.416564+00:00", "lang": "en", "topics": ["developer-tools", "artificial-intelligence", "machine-learning", "large-language-models", "ai-tools"], "entities": ["Cursor", "Claude", "Jest", "Vitest", "pytest", "Pest", "NestJS", "Laravel"], "alternates": {"html": "https://wpnews.pro/news/unit-test-ai-guide-zero-hallucination-cross-stack-standard", "markdown": "https://wpnews.pro/news/unit-test-ai-guide-zero-hallucination-cross-stack-standard.md", "text": "https://wpnews.pro/news/unit-test-ai-guide-zero-hallucination-cross-stack-standard.txt", "jsonld": "https://wpnews.pro/news/unit-test-ai-guide-zero-hallucination-cross-stack-standard.jsonld"}}