-
Notifications
You must be signed in to change notification settings - Fork 50
5. Testing
This section provides an overview of the tests included in the test
folders and instructions on how to run them.
The hng_boilerplate_golang_web
project includes tests to ensure the functionality and reliability of the codebase. Tests are organized in the test
directory, which includes unit tests, integration tests, and end-to-end tests.
The hng_boilerplate_golang_web
project includes tests to ensure the functionality and reliability of the codebase. Tests are organized in the test
directory, which includes unit tests, integration tests, and end-to-end tests.
hng_boilerplate_golang_web/
├── test/
│ ├── unit/
│ │ └── example_test.go
│ ├── integration/
│ │ └── example_integration_test.go
│ └── e2e/
│ └── example_e2e_test.go
- unit/: Contains unit tests that test individual components or functions in isolation.
- integration/: Contains integration tests that test the interactions between multiple components.
- e2e/: End-to-end tests testing the entire application flow.
Tests in Go are written using the built-in testing
package. Each test file should follow the naming convention *_test.go
, and each test function should start with the word Test
.
package unit
import (
"testing"
)
func TestExampleFunction(t *testing.T) {
result := ExampleFunction()
expected := "expected result"
if result != expected {
t.Errorf("Expected %s but got %s", expected, result)
}
}
package integration
import (
"testing"
)
func TestExampleIntegration(t *testing.T) {
// Setup code
// Call the function that integrates multiple components
// Assertions
}
package e2e
import (
"testing"
)
func TestExampleE2E(t *testing.T) {
// Setup code
// Simulate user actions
// Assertions
}
To run all tests in the project, navigate to the project root directory and execute the following command:
go test ./...
To run tests in a specific directory, navigate to that directory and execute the go test
command. For example, to run all unit tests:
cd test/unit
go test