content/guides/angular/run-tests.md
Complete all the previous sections of this guide, starting with Containerize Angular application.
Testing is a critical part of the development process. In this section, you'll learn how to:
The docker-angular-sample project comes pre-configured with Jasmine, so you can get started quickly without extra setup.
The docker-angular-sample application includes a sample test file at the following location:
$ src/app/app.component.spec.ts
This test uses Jasmine to validate the AppComponent logic.
Add a new service named angular-test to your compose.yaml file. This service allows you to run your test suite in an isolated, containerized environment.
services:
angular-dev:
build:
context: .
dockerfile: Dockerfile.dev
ports:
- "5173:5173"
develop:
watch:
- action: sync
path: .
target: /app
angular-prod:
build:
context: .
dockerfile: Dockerfile
image: docker-angular-sample
ports:
- "8080:8080"
angular-test:
build:
context: .
dockerfile: Dockerfile.dev
command: ["npm", "run", "test"]
The angular-test service reuses the same Dockerfile.dev used for development and overrides the default command to run tests with npm run test. This setup ensures a consistent test environment that matches your local development configuration.
After completing the previous steps, your project directory should contain the following files:
├── docker-angular-sample/
│ ├── Dockerfile
│ ├── Dockerfile.dev
│ ├── .dockerignore
│ ├── compose.yaml
│ ├── nginx.conf
│ └── README.Docker.md
To execute your test suite inside the container, run the following command from your project root:
$ docker compose run --rm angular-test
This command will:
angular-test service defined in your compose.yaml file.npm run test script using the same environment as development.docker compose run --rm command.You should see output similar to the following:
Test Suites: 1 passed, 1 total
Tests: 3 passed, 3 total
Snapshots: 0 total
Time: 1.529 s
[!NOTE] For more information about Compose commands, see the Compose CLI reference.
In this section, you learned how to run unit tests for your Angular application inside a Docker container using Jasmine and Docker Compose.
What you accomplished:
angular-test service in compose.yaml to isolate test execution.Dockerfile.dev to ensure consistency between dev and test environments.docker compose run --rm angular-test.Explore official references and best practices to sharpen your Docker testing workflow:
compose.yaml.docker compose run CLI reference – Run one-off commands in a service container.Next, you’ll learn how to set up a CI/CD pipeline using GitHub Actions to automatically build and test your Angular application in a containerized environment. This ensures your code is validated on every push or pull request, maintaining consistency and reliability across your development workflow.