ngt 1.0.30

There is a newer version of this package available.
See the version list below for details.
dotnet tool install --global ngt --version 1.0.30
                    
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest
                    
if you are setting up this repo
dotnet tool install --local ngt --version 1.0.30
                    
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=ngt&version=1.0.30
                    
nuke :add-package ngt --version 1.0.30
                    

ngt - Angular Unit Test Generator

CI Publish to NuGet NuGet NuGet Downloads License: MIT

A .NET CLI tool to automatically generate Jest, Vitest, or Jasmine/Karma unit tests for Angular TypeScript files with 80% test coverage target.

Features

  • Global .NET Tool - Install once, use anywhere with the ngt command
  • Runner-Aware - Auto-detects the workspace's test runner (Vitest, Jest, or Jasmine/Karma) and emits the matching mock API (vi.fn(), jest.fn(), or jasmine.createSpy())
  • Smart File Detection - Automatically identifies components, services, guards, interceptors, pipes, directives, and resolvers
  • Modern Angular Support - Handles both functional (arrow function) and class-based patterns
  • Standalone Components - Detects and properly tests standalone components and directives
  • Dependency Detection - Automatically mocks HttpClient, Router, AuthService, and injection tokens
  • Overwrite by Default - Regenerates name.spec.ts in place; pass --overwrite false to keep existing specs and write numbered files instead (e.g., .spec.2.ts)
  • Workspace Aware - Automatically detects Angular workspaces via angular.json

Quick Start

Installation

Install the tool globally from NuGet:

dotnet tool install --global ngt
Updating to the latest version

If an older version is already installed, dotnet tool install fails with Tool 'ngt' is already installed. Use update instead to pull the latest version from NuGet:

dotnet tool update --global ngt

Verify which version you have at any time:

ngt --version              # version of the installed tool
dotnet tool list --global  # all global tools and their versions

Usage

Navigate to your Angular project and generate tests:

cd /path/to/angular-app/src/app
ngt generate

Or specify a path:

ngt generate --path /path/to/angular/app

Example Output

Detected Angular workspace at: /home/user/my-angular-app
Generating tests for: /home/user/my-angular-app/src/app
Found 12 TypeScript file(s) to process.

✓ Generated: app.component.spec.ts
✓ Generated: user.service.spec.ts
✓ Generated: auth.guard.spec.ts
✓ Generated: auth.interceptor.spec.ts
✓ Generated: date-format.pipe.spec.ts
- Skipped: user.model (interface/type only)

Test generation complete:
  Success: 10
  Skipped: 2
  Failed: 0
  Total: 12

Supported File Types

Type File Pattern Features
Components *.component.ts TestBed, fixtures, standalone detection
Services *.service.ts HTTP mocking, method-level tests
Guards *.guard.ts Functional & class-based, auth mocking
Interceptors *.interceptor.ts HTTP testing, token injection
Pipes *.pipe.ts Transform testing
Directives *.directive.ts Host component testing
Resolvers *.resolver.ts Route data resolution

Documentation

Prerequisites

  • .NET 9.0 SDK or later
  • An Angular application with TypeScript files

Command Reference

Generate Command

ngt generate [options]
Option Alias Description
--path -p Path to generate tests for (optional)
--overwrite -o Overwrite an existing .spec.ts in place (default: true). Use --overwrite false to keep existing specs and write .spec.2.ts, .spec.3.ts, …
--help -h Show help

Global Options

ngt --version    # Show version
ngt --help       # Show help

Configuration

Create appsettings.json in your project to customize behavior:

{
  "AngularTestGenerator": {
    "TargetCoveragePercentage": 80,
    "TestFileExtension": ".spec.ts",
    "ExcludedDirectories": ["node_modules", "dist", ".angular", "coverage"]
  }
}

See Configuration Guide for all options.

How It Works

  1. Discovery - Scans the directory for TypeScript files, excluding node_modules, dist, and existing test files
  2. Analysis - Determines file type, extracts class names, detects dependencies, and identifies patterns (functional vs class-based)
  3. Generation - Creates appropriate test files with TestBed configuration, mocks, and basic test cases
  4. Naming - Regenerates name.spec.ts in place by default; with --overwrite false, an existing spec is preserved and a discriminating number is added instead (e.g., .spec.2.ts)

Project Structure

src/AngularUnitTests.Cli/
├── Commands/           # CLI command definitions
├── Services/           # Core services (discovery, generation)
├── Models/             # Data models
├── Configuration/      # Options and settings
└── Program.cs          # Entry point

Development

Build from Source

git clone https://github.com/QuinntyneBrown/AngularUnitTests.git
cd AngularUnitTests
dotnet build

Run Tests

dotnet test

Install Local Build

dotnet pack src/AngularUnitTests.Cli/AngularUnitTests.Cli.csproj -o ./nupkg
dotnet tool install --global --add-source ./nupkg ngt

Continuous Integration & Publishing

Workflow Trigger What it does
CI push / PR to main Restores, builds, and tests the solution on Linux, Windows, and macOS
Publish to NuGet push to main / manual Builds, tests, packs, and pushes ngt to NuGet with --skip-duplicate

Publishing pushes the package only when the <Version> in AngularUnitTests.Cli.csproj is new, so bump it to cut a release. The workflow requires a NUGET_API_KEY repository secret.

Contributing

Contributions are welcome! Please read CONTRIBUTING.md and follow our Code of Conduct.

License

MIT — see LICENSE.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last Updated
1.0.43 102 6/14/2026
1.0.42 102 6/10/2026
1.0.41 93 6/10/2026
1.0.40 103 6/10/2026
1.0.34 105 6/6/2026
1.0.33 104 6/5/2026
1.0.32 105 6/5/2026
1.0.30 98 6/1/2026
1.0.29 95 6/1/2026
1.0.3 152 2/9/2026
1.0.2 117 2/5/2026
1.0.1 117 2/5/2026
1.0.0 117 2/5/2026