← 返回命令列表

Linux command

ng-test 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Run unit tests

ng test

Run tests for a specific project

ng test [project-name]

Run tests without watching

ng test --no-watch

Run tests with code coverage

ng test --code-coverage

Run tests in a specific browser

ng test --browsers [ChromeHeadless]

Run a single test run

ng test --watch=false

说明

ng test compiles the application and runs unit tests using the configured test runner. By default, Angular CLI uses Karma as the test runner with Jasmine as the testing framework. Tests run in a browser and re-execute automatically when source files change. The command watches for file changes by default, providing a continuous testing workflow during development.

参数

--code-coverage
Generate a code coverage report in the coverage/ directory.
--watch
Re-run tests when files change (default: true).
--browsers _browsers_
Override browsers to launch for testing (e.g., ChromeHeadless).
--configuration _name_
Target build configuration.
--karma-config _path_
Path to Karma configuration file.
--include _glob_
Glob pattern of files to include in testing.
--help
Display help information.

FAQ

What is the ng-test command used for?

ng test compiles the application and runs unit tests using the configured test runner. By default, Angular CLI uses Karma as the test runner with Jasmine as the testing framework. Tests run in a browser and re-execute automatically when source files change. The command watches for file changes by default, providing a continuous testing workflow during development.

How do I run a basic ng-test example?

Run `ng test` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does --code-coverage do in ng-test?

Generate a code coverage report in the coverage/ directory.