Running Tests for slimtoolkit/slim
This document provides a step-by-step guide for running tests for the slimtoolkit/slim project.
Running Tests with make
The project’s Makefile
provides convenient targets for running tests. You can use make
to execute these targets:
Run tests:
make test
This target builds the project, runs tests, and generates coverage reports.
Source:
Makefile
Running Tests with go test
You can also run tests using the go test
command. This approach offers more granular control over the testing process.
Run all tests:
go test ./...
This command runs all tests within the project’s directory.
Run tests in a specific package:
go test ./path/to/package
Replace
./path/to/package
with the actual path to the package you want to test.Run tests with specific flags:
go test -v ./...
The
-v
flag enables verbose output, providing detailed information about test execution.You can also use other flags like
-cover
to generate coverage reports,-run
to filter tests by name, and-bench
to run benchmarks.Source:
go help test
Generating Coverage Reports
To generate a test coverage report, you can use the go test -cover
command. This command creates a coverage report in the coverage.out
file.
Generate coverage report:
go test -cover ./...
This command runs all tests and generates a coverage report in
coverage.out
.View coverage report:
go tool cover -html=coverage.out
This command opens the coverage report in your web browser.
Source:
go help test
Running Tests in a Docker Container
The project provides a Dockerfile
for building and running the application in a Docker container. You can use the make
command to build and run the container.
Build the Docker image:
make build_in_docker
This target builds a Docker image named
slim
with the project’s code.Run the Docker container:
make run_in_docker
This target runs the Docker container and exposes port
8080
to the host machine.Source:
Dockerfile
,Makefile
Running Tests with make test
(Simplified)
For a simplified approach, use the make test
target to run the tests within the Docker container:
make test
This approach simplifies the testing process by automatically building the Docker image and running the tests within the container.
Source: Makefile